GPUImage: blending two images

﹥>﹥吖頭↗ 提交于 2019-11-29 03:33:07

问题


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?


回答1:


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.




回答2:


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];


来源:https://stackoverflow.com/questions/11608332/gpuimage-blending-two-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!