iOS - 无法使用 CIFilter 处理图像
我正在尝试使用 Core Image 处理图像。我创建了 UIImage 类别来做到这一点。
我已将 QuartzCore 和 CoreImage 框架添加到项目中,导入 CoreImage/CoreImage.h 并使用此代码:
CIImage *inputImage = self.CIImage;
CIFilter *exposureAdjustmentFilter = [CIFilter filterWithName:@"CIExposureAdjust"];
[exposureAdjustmentFilter setDefaults];
[exposureAdjustmentFilter setValue:inputImage forKey:@"inputImage"];
[exposureAdjustmentFilter setValue:[NSNumber numberWithFloat:5.0f] forKey:@"inputEV"];
CIImage *outputImage = [exposureAdjustmentFilter valueForKey:@"outputImage"];
CIContext *myContext = [CIContext contextWithOptions:nil];
return [UIImage imageWithCGImage:[myContext createCGImage:outputImage fromRect:outputImage.extent]];
但我有 nil 过滤器的输出图像。
我也尝试使用 CIHueAdjust 得到相同的结果。
比你提前
更新:我已经找到了解决方案。有必要分配新的CIImage,而不仅仅是通过这种方式传递对UIImage.CIImage的引用:
CIImage *inputImage = [[CIImage alloc] initWithImage:self];
I am trying to process image using Core Image. I have created UIImage category to do it.
I have added QuartzCore and CoreImage frameworks to project, imported CoreImage/CoreImage.h and used this code:
CIImage *inputImage = self.CIImage;
CIFilter *exposureAdjustmentFilter = [CIFilter filterWithName:@"CIExposureAdjust"];
[exposureAdjustmentFilter setDefaults];
[exposureAdjustmentFilter setValue:inputImage forKey:@"inputImage"];
[exposureAdjustmentFilter setValue:[NSNumber numberWithFloat:5.0f] forKey:@"inputEV"];
CIImage *outputImage = [exposureAdjustmentFilter valueForKey:@"outputImage"];
CIContext *myContext = [CIContext contextWithOptions:nil];
return [UIImage imageWithCGImage:[myContext createCGImage:outputImage fromRect:outputImage.extent]];
But I have got nil output image from the filter.
I have also tried to use CIHueAdjust with the same result.
Than you in advance
UPDATE: I have found solution. It was necessary to alloc new CIImage, not only pass reference to UIImage.CIImage this way:
CIImage *inputImage = [[CIImage alloc] initWithImage:self];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下代码:-
Try following code:-