gpt4 book ai didi

ios - Objective-C : CIFilter returning nil image

转载 作者:行者123 更新时间:2023-11-28 21:23:22 26 4
gpt4 key购买 nike

我正在编写一个函数,它将对图像应用滤镜并返回新图像。我写了下面的代码:

+ (UIImage*)applyFilter:(UIImage*) photo {
CIImage *image = [[CIImage alloc] initWithCGImage:photo.CGImage];
CIFilter *filter = [CIFilter filterWithName:@"CIphotoEffectTransfer"
keysAndValues: kCIInputImageKey, image,
@"inputIntensity", @0.8, nil];
CIImage *outputImage = [filter outputImage];

UIImage* newPhoto = [self imageFromCIImage:outputImage];
return newPhoto;
}

我遇到的问题是该函数返回的是一张无照片,而不是应用了滤镜的照片。有趣的是,如果我将过滤器名称更改为@"CIVignetteEffect",它将起作用。我不明白为什么一个过滤器有效而另一个过滤器无效。我从以下链接找到了两个过滤器:https://developer.apple.com/library/tvos/documentation/GraphicsImaging/Reference/CoreImageFilterReference/index.html#//apple_ref/doc/filter/ci/CIPhotoEffectTransfer

最佳答案

我认为滤镜的正确名称是 CIPhotoEffectTransfer,而不是 CIphotoeffectTransfer。

试试这个代码...我过去用它来过滤照片,所以我知道它有效:

+ (UIImage*)applyFilter:(UIImage*) photo {
UIImageOrientation orientation = photo.imageOrientation;
CIImage* image = [CIImage imageWithCGImage:photo.CGImage];
CIContext *context = [CIContext contextWithOptions:nil];
CIFilter *filter = [CIFilter filterWithName:@"CIPhotoEffectTransfer"];
[filter setValue:image forKey:kCIInputImageKey];
CIImage *outputImage = [filter outputImage];
CGImageRef cgimg = [context createCGImage:outputImage fromRect:[outputImage extent]];
UIImage *newPhoto = [UIImage imageWithCGImage:cgimg scale:1.0 orientation:orientation];
CGImageRelease(cgimg);
context = nil;
return newPhoto;

关于ios - Objective-C : CIFilter returning nil image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39028234/

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