CIGaussianBlur and CIAffineClamp on iOS 6

风流意气都作罢 提交于 2019-11-27 05:59:43

问题


I am trying to blur an image using CoreImage on iOS 6 without having a noticeable black border. Apple documentation states that using a CIAffineClamp filter can achieve this but I'm not able to get an output image from the filter. Here's what I tried, but unfortunately an empty image is created when I access the [clampFilter outputImage]. If I only perform the blur an image is produced, but with the dark inset border.

CIImage *inputImage = [[CIImage alloc] initWithCGImage:self.CGImage];

CIContext *context = [CIContext contextWithOptions:nil];

CGAffineTransform transform = CGAffineTransformIdentity;

CIFilter *clampFilter = [CIFilter filterWithName:@"CIAffineClamp"];
[clampFilter setValue:inputImage forKey:kCIInputImageKey];
[clampFilter setValue:[NSValue valueWithBytes:&transform objCType:@encode(CGAffineTransform)] forKey:@"inputTransform"];

CIImage *outputImage = [clampFilter outputImage];

CIFilter *blurFilter = [CIFilter filterWithName:@"CIGaussianBlur"
     keysAndValues:kCIInputImageKey, outputImage, @"inputRadius", [NSNumber numberWithFloat:radius], nil];

outputImage = [blurFilter outputImage];

CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *blurredImage = [UIImage imageWithCGImage:cgimg];
CGImageRelease(cgimg);

回答1:


The CIAffineClamp filter is setting your extent as infinite, which then confounds your context. Try saving off the pre-clamp extent CGRect, and then supplying that to the context initializer.



来源:https://stackoverflow.com/questions/12910625/cigaussianblur-and-ciaffineclamp-on-ios-6

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!