gpt4 book ai didi

ios - CIImage大小范围为零?

转载 作者:行者123 更新时间:2023-12-01 19:59:24 25 4
gpt4 key购买 nike

我创建了此类别,将CIImage转换为UIImage。我正在使用的CIImage来自CIFilter

-(UIImage *)obtainImageWithRetinaScale:(CGFloat)scale
{
CIContext *context = [CIContext contextWithOptions:nil];

//CGRect frame = CGRectMake(0,0,700,392);
CGImageRef processedCGImage = [context createCGImage:self
fromRect:[self extent]];

UIImage *returnImage = [UIImage imageWithCGImage:processedCGImage
scale:scale
orientation:UIImageOrientationUp];
CGImageRelease(processedCGImage);

return returnImage;
}

运行此命令时, [self extent]给出的rect带有乱码,几乎没有(0、0,无穷大,无穷大)...那里真的有很大的数字。

显然处理的图像为零。

当我以正确的大小强制构图时,会正确生成图像。

最佳答案

使用以下代码,功劳完全归功于他的答案William Vasconcelos中的here,这就是为什么我将其设置为社区Wiki:

//assume beginImage is CIImage you want to tint            
CIImage* outputImage = nil;

//create some blue
CIFilter* blueGenerator = [CIFilter filterWithName:@"CIConstantColorGenerator"];
CIColor* blue = [CIColor colorWithString:@"0.1 0.5 0.8 1.0"];
[blueGenerator setValue:blue forKey:@"inputColor"];
CIImage* blueImage = [blueGenerator valueForKey:@"outputImage"];

//apply a multiply filter
CIFilter* filterm = [CIFilter filterWithName:@"CIMultiplyCompositing"];
[filterm setValue:blueImage forKey:@"inputImage"];
[filterm setValue:beginImage forKey:@"inputBackgroundImage"];
outputImage = [filterm valueForKey:@"outputImage"];

为了带来一些个人贡献并使之值得回答,以下是Swift 3版本:
// assume beginImage is the CIImage you want to tint
let outputImage: CIImage?
let blueGenerator = CIFilter(name: "CIConstantColorGenerator", withInputParameters: ["inputColor": CIColor(string: "0.1 0.5 0.8 1.0")])
let blueImage = blueGenerator!.outputImage

let filterM = CIFilter(name: "CIMultiplyCompositing", withInputParameters: ["inputImage": blueImage, "inputBackgroundImage": beginImage])
outputImage = filterM.outputImage

关于ios - CIImage大小范围为零?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40655265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com