Question

I devlop an app, where I can apply overlays on a custom image.

I have this code. But every time I'll run the app it crashes. I hope someone knows what I have to do.

Code:

    NSString *filename = @"Overlay1.png";

GPUImageMultiplyBlendFilter *overlayBlendFilter = [[GPUImageMultiplyBlendFilter alloc] init];
GPUImagePicture *pic1 = [[GPUImagePicture alloc] initWithImage:imgView.image];
GPUImagePicture *pic2 = [[GPUImagePicture alloc] initWithImage:[UIImage imageNamed:filename]];

[pic1 addTarget:overlayBlendFilter];
[pic1 processImage];
[pic2 addTarget:overlayBlendFilter];
[pic2 processImage];
[overlayBlendFilter useNextFrameForImageCapture];


UIImage *blendedImage = [overlayBlendFilter imageFromCurrentFramebufferWithOrientation:imgView.image.imageOrientation];

NSDictionary *filteredDictionary = [[NSDictionary alloc] initWithObjectsAndKeys:blendedImage, @"filteredImage", filename, @"filename", nil];

[filterNames insertObject:filteredDictionary atIndex:0];
Was it helpful?

Solution

You haven't told us where this is crashing, but I'd bet that it's crashing due to you trying to insert a nil value into your dictionary. (Next time, please look for anything being logged to the console when asking a question like this.)

That nil image is going to come from the fact that you've put your -useNextFrameForImageCapture in the wrong place. It need to go before the -processImage calls in the above, which are what triggers the actual rendering to your filter.

I bet if you move that line back, you'll no longer get a nil image and will no longer crash.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top