CIGaussianBlur的正确裁剪 [英] Correct crop of CIGaussianBlur
问题描述
正如我注意到的那样,当将CIGaussianBlur应用于图像时,图像的角变得模糊,因此看起来比原始图像要小.因此,我发现我需要正确裁剪它,以免图像出现透明边缘.但是如何根据模糊量来计算需要裁剪多少呢?
As I noticed when CIGaussianBlur is applied to image, image's corners gets blurred so that it looks like being smaller than original. So I figured out that I need to crop it correctly to avoid having transparent edges of image. But how to calculate how much I need to crop in dependence of blur amount?
示例:
原始图片:
Original image:
CIGaussianBlur输入半径为50的图像(蓝色是所有内容的背景):
Image with 50 inputRadius of CIGaussianBlur (blue color is background of everything):
推荐答案
以下面的代码为例...
Take the following code as an example...
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [[CIImage alloc] initWithImage:image];
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setValue:inputImage forKey:kCIInputImageKey];
[filter setValue:[NSNumber numberWithFloat:5.0f] forKey:@"inputRadius"];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef cgImage = [context createCGImage:result fromRect:[result extent]];
这将产生您上面提供的图像.但是,如果我改用原始图像rect来根据上下文创建CGImage,则结果图像将为所需大小.
This results in the images you provided above. But if I instead use the original images rect to create the CGImage off of the context the resulting image is the desired size.
CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];
这篇关于CIGaussianBlur的正确裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!