objective-c - 正确裁剪 CIGaussianBlur

标签 objective-c macos core-image

正如我注意到的,当将 CIGaussianBlur 应用于图像时,图像的角变得模糊,因此它看起来比原始图像小。所以我发现我需要正确裁剪它以避免图像的透明边缘。但是如何根据模糊量计算我需要裁剪多少?


例子:

原图:
enter image description here

具有 50 个 CIGaussianBlur 输入半径的图像(蓝色是所有内容的背景):
enter image description here

最佳答案

以下面的代码为例...

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,则生成的图像就是所需的大小。

CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];

关于objective-c - 正确裁剪 CIGaussianBlur,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12839729/

相关文章:

ios - 我需要一种方法来检索和记录通过 USB 连接的 iPhone 设备的 IMEI、序列号、ICCID 和 MEID

macos - 尝试从 Go 应用启动终端时出现 "exit status 1"

ios - 如何使用CIContext drawImage :inRect:fromRect: with a CADisplayLink

ios - [CustomCell setImageView :]: unrecognized selector

objective-c - NSOutlineView 的自动保存扩展项不起作用

ios - UIView 底边模式

macos - Python : Error Handling

iphone - 使用 iPhone sdk 从 URL 加载 ImageView 中的图像?

cocoa - 如何使用 Core Image 滤镜有效地平衡图像的色彩?

ios - 调整 CVPixelBuffer 的大小