我們在少數圖像上應用了「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;
}
過濾 )
後過濾
嘿鄧肯!會喜歡這個:)的快速版本 –