Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GPUImage: blending two images

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?

like image 559
Nikita Avatar asked Jul 23 '12 07:07

Nikita


2 Answers

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.

like image 73
Brad Larson Avatar answered Nov 10 '22 08:11

Brad Larson


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];
like image 30
emrahgunduz Avatar answered Nov 10 '22 08:11

emrahgunduz