I was using GPUImage framework (some old version) to blend two images (adding border overlay to a certain image). After I have updated to latest framework version, after applying such a blend, I get an empty black image.
I'm using next method:
- (void)addBorder {
if (currentBorder != kBorderInitialValue) {
GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
GPUImagePicture *imageToProcess = [[GPUImagePicture alloc] initWithImage:self.imageToWorkWithView.image];
GPUImagePicture *border = [[GPUImagePicture alloc] initWithImage:self.imageBorder];
blendFilter.mix = 1.0f;
[imageToProcess addTarget:blendFilter];
[border addTarget:blendFilter];
[imageToProcess processImage];
self.imageToWorkWithView.image = [blendFilter imageFromCurrentlyProcessedOutput];
[blendFilter release];
[imageToProcess release];
[border release];
}
}
What is the problem?
You're forgetting to process the border image. After [imageToProcess processImage]
, add the line:
[border processImage];
For a two images being input into a blend, you have to use -processImage
on both after they have been added to the blend filter. I changed the way that the blend filter works in order to fix some bugs, and this is how you need to do things now.
This is the code I'm currently using for merging two images with GPUImageAlphaBlendFilter.
GPUImagePicture *mainPicture = [[GPUImagePicture alloc] initWithImage:image];
GPUImagePicture *topPicture = [[GPUImagePicture alloc] initWithImage:blurredImage];
GPUImageAlphaBlendFilter *blendFilter = [[GPUImageAlphaBlendFilter alloc] init];
[blendFilter setMix:0.5];
[mainPicture addTarget:blendFilter];
[topPicture addTarget:blendFilter];
[blendFilter useNextFrameForImageCapture];
[mainPicture processImage];
[topPicture processImage];
UIImage * mergedImage = [blendFilter imageFromCurrentFramebuffer];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With