GPUImage:混合两个图像

时间:2012-07-23 07:48:24

标签: iphone objective-c image-processing gpuimage

我正在使用GPUImage框架(一些旧版本)来混合两个图像(将边框叠加添加到某个图像)。 在我更新到最新的框架版本后,应用这样的混合后,我得到一个空的黑色图像。

我正在使用下一个方法:

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

有什么问题?

2 个答案:

答案 0 :(得分:11)

您忘记处理边框图像。在[imageToProcess processImage]之后,添加以下行:

[border processImage];

如果要将两个图像输入到混合中,则必须在将它们添加到混合滤镜后使用-processImage。我改变了混合滤镜的工作方式以修复一些错误,这就是你现在需要做的事情。

答案 1 :(得分:7)

这是我目前用于将两个图像与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];
相关问题