问题描述
我正在使用这样的解决方案来用一些Alpha绘图遮罩我的UIImage
:屏蔽UIImage
I'm using such solution to mask my UIImage
with some alpha drawing:masking an UIImage
问题是以后我要应用一些CIFilters
.但是,当我更改过滤器的值时,我的alpha从UIImage
中丢失了.每次修改CIFilter后,是否都必须重新应用alpha通道来输出图像?这肯定会使该过程变慢.
The problem is that later i want to apply some CIFilters
. However when i change value of the filter, my alpha gets lost from UIImage
. Do i have to re-apply the alpha channel to output image each time after modifying CIFilter? This will surely make the process much slower.
代码示例:(每个新段落在另一种方法中)
Samples of code: (each new paragraph is in another method)
// 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];
推荐答案
您只能使用CIFilters执行此操作.可以使用CIBlendWithMask
CIFilter代替使用imageWithMask
. Apple CIFilter参考
you could do this only using CIFilters. Instead of using imageWithMask
you can use the CIBlendWithMask
CIFilter. Apple CIFilter Reference
这篇关于CIFilter + UIImage + Alpha蒙版的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!