CIBloom使图像更小

问题描述 投票:3回答:2

我正在使用CIBloom来模糊CGImage中的一些文本,但是发生的事情是CIBloom过滤器似乎使我的图像变得非常小。

当滤波器内核变大时,效果会更差。我有点期待这个,但我需要一种方法来关闭它,或者一个公式来调整图像的大小,以便每个字母的大小与它原来的大小完全相同。我故意在源图像上留下边距。

在CIBloom过滤之前:

CIBloom过滤后:

模糊过滤器的代码:

CGImageRef cgImageRef = CGBitmapContextCreateImage( tex->cgContext ) ;

CIImage *cii = [CIImage imageWithCGImage:cgImageRef] ;

CIFilter *filter = [CIFilter filterWithName:@"CIBloom"] ; //CIGaussianBlur

[filter setValue:cii forKey:kCIInputImageKey];
[filter setValue:[NSNumber numberWithFloat:1.1f] forKey:@"inputIntensity"];

// Large radius makes result EVEN SMALLER:
//[filter setValue:[NSNumber numberWithFloat:100.f] forKey:@"inputRadius"];

CIContext *ciContext = [CIContext contextWithOptions:nil];

CIImage *ciResult = [filter valueForKey:kCIOutputImageKey];
CGImageRef cgIRes = [ciContext createCGImage:ciResult fromRect:[ciResult extent]];

//Clear old tex
tex->clearBacking( 0, 0, 0, 1 ) ;

// Drop CIImage result into texture raw data
CGContextDrawImage( tex->cgContext, CGRectMake(0, 0, tex->w, tex->h), cgIRes ) ;

我喜欢CIBloom滤镜,但我需要的结果与原始图像的尺寸相同,而不是缩减采样。

cgimage ciimage
2个回答
2
投票

好吧,为默认内核大小10添加到图像的额外空间是21x28。

对于K = 10,所得图像每侧加21px,顶部和底部加28px。请记住,支持是768x1024像素,看起来放大产生的图像为810x1080。

玩弄这个,我想出了以下内容

CGContextDrawImage( tex->cgContext, CGRectMake(-30, -36, tex->w+2*30, tex->h+2*36), cgIRes ) ;

这似乎非常近似(必须有一个公式)并引入一些失真,但它的作用是使图像几乎与原来的大小相同,而不引入边框。


0
投票

绽放效果会更改原始图像的位置和大小。所以你需要重新编辑它们。 在您的情况下,您更改以下代码行:

CGImageRef cgIRes = [ciContext createCGImage:ciResult fromRect:[ciResult extent]];

CGImageRef cgIRes = [ciContext createCGImage:ciResult fromRect:[cii extent]];

希望它能帮到你

© www.soinside.com 2019 - 2024. All rights reserved.