【问题标题】:GPUImage: blending two imagesGPUImage:混合两个图像
【发布时间】:2012-07-23 07:48:23
【问题描述】:

我正在使用 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];
    }
}

有什么问题?

【问题讨论】:

    标签: iphone objective-c image-processing gpuimage


    【解决方案1】:

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

    [border processImage];
    

    对于要输入到混合中的两个图像,在将它们添加到混合过滤器后,您必须对它们都使用-processImage。我更改了混合过滤器的工作方式以修复一些错误,这就是您现在需要做的事情。

    【讨论】:

    • @BradLarson:布拉德,我可以在混合文件中添加两张以上的图片以创建乘法效果吗?我有多个图层和一个背景。我想使用两个以上的 [第 1 层和背景层] 创建 sme nice 效果。谢谢!
    • 你好,有没有关于如何使用GPUImageAlphaBlendFilter 和实时GPUImageStillCamera 的资源,它没有processImage 方法?我在这里问了一个关于我的问题的问题stackoverflow.com/questions/16384813/…
    • imageFromCurrentlyProcessedOutput 给出最新的 guimage 和 ios8 错误。我也使用了imageFromCurrentFramebufferWithOrientation:0,但仍然报错。
    • @RahulRD 我认为不再有 imageFromCurrentlyProcessedOutput 这样的东西了。使用此答案中的代码,我也遇到了崩溃。你最后是怎么解决的?
    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-01
      • 2014-05-18
      • 1970-01-01
      相关资源
      最近更新 更多