【发布时间】:2013-08-21 08:39:56
【问题描述】:
我们正在对少数图像应用“CIGaussianBlur”滤镜。该过程大部分时间都运行良好。但是当应用程序移动到后台时,该过程会在图像上产生白色条纹。 (下图,请注意图像的左侧和底部是白色条纹,与原始图像相比,图像有点尖叫)。
代码:
- (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;
}
过滤前 )
过滤后
【问题讨论】: