我试图在 iOS 6 上使用 CoreImage 模糊图像而没有明显的黑色边框。Apple 文档指出,使用 CIAffineClamp 过滤器可以实现这一点,但我无法从过滤器中获取输出图像。这是我尝试过的,但不幸的是,当我访问 [clampFilter outputImage] 时会创建一个空图像。如果我只执行模糊,则会生成图像,但带有深色嵌入边框。
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);