我们在少数图像上应用了“CIGaussianBlur”过滤器。这个过程大部分时间都运行良好。但是当应用程序移动到背景时,该过程会在图像上产生白色条纹。 (下面的图片,请注意,图像的左侧和底部被条纹化为白色,并且图像与原始图像相比有点尖叫)。当应用程序处于后台时,CIFilter无法正常工作
验证码:
- (UIImage*)imageWithBlurRadius:(CGFloat)radius
{
UIImage *image = self;
LOG(@"(1) image size before resize = %@",NSStringFromCGSize(image.size));
NSData *imageData = UIImageJPEGRepresentation(self, 1.0);
LOG(@"(2) image data length = %ul",imageData.length);
//create our blurred image
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [CIImage imageWithCGImage:image.CGImage];
//setting up Gaussian Blur (we could use one of many filters offered by Core Image)
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setValue:inputImage forKey:kCIInputImageKey];
[filter setValue:[NSNumber numberWithFloat:radius] forKey:@"inputRadius"];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
//CIGaussianBlur has a tendency to shrink the image a little, this ensures it matches up exactly to the bounds of our original image
CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];
UIImage *finalImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
LOG(@"(3) final image size after resize = %@",NSStringFromCGSize(finalImage.size));
return finalImage;
}
过滤 )
后过滤
嘿邓肯!会喜欢这个:)的快速版本 –