iOS 6上的CIGaussianBlur和CIAffineClamp [英] CIGaussianBlur and CIAffineClamp on iOS 6
问题描述
我试图在iOS 6上使用CoreImage模糊图像而没有明显的黑色边框。 Apple文档声明使用CIAffineClamp过滤器可以实现此目的,但我无法从过滤器获取输出图像。这是我尝试过的,但不幸的是,当我访问[clampFilter outputImage]时会创建一个空图像。如果我只执行模糊,则会产生图像,但是使用黑色插入边框。
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);
推荐答案
CIAffineClamp过滤器将您的范围设置为无限,然后混淆你的背景。尝试保存预钳位范围CGRect,然后将其提供给上下文初始化程序。
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.
这篇关于iOS 6上的CIGaussianBlur和CIAffineClamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!