CIFilter + UIImage + alpha蒙版

时间:2013-08-16 12:48:29

标签: ios objective-c mask cifilter

我正在使用这样的解决方案用一些alpha绘图来掩盖我的UIImagemasking an UIImage

问题是后来我想申请一些CIFilters。但是,当我更改过滤器的值时,我的alpha会从UIImage中丢失。每次修改CIFilter后,是否必须重新应用alpha通道输出图像?这肯定会使这个过程慢得多。

代码示例:(每个新段落采用另一种方法)

// set the image
_image = [incomeImage imageWithMask:_mask]; // imageWithMask from method from link
[_myView.imageView setImage:_image];

// calculate ciimages
_inputCIImage = [[CIImage alloc] initWithCGImage:_image.CGImage options:nil];
_myView.imageView.image = _image;
_currentCIImage = _inputCIImage;

// change value in filter
[filter setValue:@(0.2f) forKey:@"someKey"];
[filter setValue:_inputCIImage forKey:kCIInputImageKey];
_currentCIImage = [filter outputImage];
CGImageRef img = [_context createCGImage:_currentCIImage fromRect:[_currentCIImage extent]];
UIImage *newImage = [UIImage imageWithCGImage:img];

1 个答案:

答案 0 :(得分:3)

你只能使用CIFilters来做到这一点。您可以使用imageWithMask CIFilter而不是CIBlendWithMaskApple CIFilter Reference