当使用CIFilter(CISourceOverCompositing)组合两个图像时,丢失了alpha通道

时间:2014-01-07 03:12:38

标签: ios objective-c core-image cifilter

我想将动画放到图像中并生成视频,所以我试图将背景图像(CIImage)和动画帧之一(CIImage)与CISourceOverCompositing过滤器合并,但我发现所有透明图像(动画帧)不再变得透明,所有的α值都被舍入(< 0.5-> 0.0,> = 0.5-> 1.0)。也许我选择了错误的过滤器,但我找不到合适的过滤器来满足我的要求。有什么好的建议吗?无论如何,谢谢你的帮助。

我写了一个非常简单的示例代码:

- (void)generateSampleImage {
CIImage *background = [CIImage imageWithContentsOfURL:
                       [[NSBundle mainBundle] URLForResource:@"background" withExtension:@"png"]];
CIImage *foreground = [CIImage imageWithContentsOfURL:
                       [[NSBundle mainBundle] URLForResource:@"foreground" withExtension:@"png"]];




CIFilter *filter = [CIFilter filterWithName:@"CISourceOverCompositing"];
[filter setValue:background forKey:kCIInputBackgroundImageKey];
[filter setValue:foreground forKey:kCIInputImageKey];
CIImage *outputImage = [filter outputImage];
self.imageView.image = [self imageWithCIImage:outputImage];




NSURL *baseUrl = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory
                                                         inDomains:NSUserDomainMask] objectAtIndex:0];
NSURL *outputUrl = [baseUrl URLByAppendingPathComponent:@"output_image.png"];
[UIImagePNGRepresentation(self.imageView.image) writeToFile:outputUrl.path atomically:YES];
}

要与之结合的背景图片: the background image to combine with 前景图像与: the foreground image to combine with 使用CISourceOverCompositing过滤器的输出图像: the output image with CISourceOverCompositing filter 我想要的理想形象: the ideal image that I want

0 个答案:

没有答案