我正在尝试使用 GPUImage 将一张图像叠加在另一张图像之上,并使用 alpha 和乘法混合。在 Core Graphics 中,这就是我所做的。
CGContextRef ctx = UIGraphicsGetCurrentContext();
UIImage* baseImage = ...;
UIImage* overImage = ...;
CGSize size = baseImage.size;
// Draw the base image
CGContextDrawImage(ctx, CGRectMake(0, 0, size.width, size.height), baseImage.CGImage);
//Draw the overlay
CGContextSetAlpha(ctx, .5);
CGContextSetBlendMode(ctx, kCGBlendModeMultiply);
CGContextDrawImage(ctx, CGRectMake(0, 0, size.width, size.height), overImage.CGImage);
当我尝试使用 GPUImage 做同样的事情时,我可以让 multiply 或 alpha 工作,但我不能让它们都工作。我觉得结合 GPUImage 过滤器有些东西我不明白。这是我使用 GPUImage 所做的许多不同尝试之一,以使其正常工作。此版本的代码正在执行乘法而不是 alpha。
GPUImagePicture *pictureOverlay = [[GPUImagePicture alloc] initWithImage:overImage];
GPUImageOpacityFilter* opacityFilter = [[GPUImageOpacityFilter alloc] init];
opacityFilter.opacity = .5;
[pictureOverlay addTarget:opacityFilter];
[pictureOverlay processImage];
pictureOverlay = [[GPUImagePicture alloc] initWithImage:[opacityFilter imageFromCurrentlyProcessedOutput]];
GPUImagePicture *pictureBase = [[GPUImagePicture alloc] initWithImage:baseImage];
GPUImageMultiplyBlendFilter *filter = [[GPUImageMultiplyBlendFilter alloc] init];
[pictureBase addTarget:filter];
[pictureOverlay addTarget:filter];
UIImage* finalImage = [filter imageFromCurrentlyProcessedOutput];
如有任何帮助,我们将不胜感激。
这是我仅使用 Core Graphics 处理时图像的样子。
这是我使用 GPUImage 时得到的结果
最佳答案
尝试以下操作,我目前正在使用 GPUImage,我认为以下操作可能适合您:
GPUImagePicture *pictureBase = [[GPUImagePicture alloc] initWithImage:baseImage];
GPUImageMultiplyBlendFilter *filter = [[GPUImageMultiplyBlendFilter alloc] init];
[pictureBase addTarget:filter];
[pictureBase processImage];
GPUImagePicture *pictureOverlay = [[GPUImagePicture alloc] initWithImage:overImage];
GPUImageOpacityFilter* opacityFilter = [[GPUImageOpacityFilter alloc] init];
opacityFilter.opacity = .5;
[pictureOverlay addTarget:opacityFilter];
[opacityFilter addTarget:filter];
[pictureOverlay processImage];
UIImage* finalImage = [filter imageFromCurrentlyProcessedOutput];
它的工作方式就像一个管道,其中来自一个过滤器的结果是下一个过滤器的入口。
关于ios - 使用 multiply 和 alpha 在另一个 GPUImage 上绘制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21990041/