正确裁剪 CIGaussianBlur [英] Correct crop of CIGaussianBlur

查看:22
本文介绍了正确裁剪 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?

示例:

原图:

具有 50 个输入半径的 CIGaussianBlur 图像(蓝色是一切的背景):

Image with 50 inputRadius of CIGaussianBlur (blue color is background of everything):

推荐答案

以下代码为例...

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆