ios - 输入图像=零: Filtered Image not displaying?

标签 ios core-image

一直在借助 bitFountain 上的在线教程开发图像过滤应用程序。用户应该能够选择他们添加到相册的照片图像,然后可以为照片添加滤镜或删除该图像。 我的删除图像功能运行良好,但添加过滤器不起作用。

我已将三个过滤器实例记录到控制台,因为它们由该方法返回,但它返回为 inputImage = nil。

2015-10-19 10:41:53.634 FilterApp[78451:28732768] <CISepiaTone: inputImage=nil inputIntensity=1>
2015-10-19 10:41:53.634 FilterApp[78451:28732768] <CIGaussianBlur: inputImage=nil inputRadius=1>
2015-10-19 10:41:53.635 FilterApp[78451:28732768] <CIColorClamp: inputImage=nil inputMinComponents=[0.2 0.2 0.2 0.2] inputMaxComponents=[0.9 0.9 0.9 0.9]>

inputImage=nil 到底是什么意思?

我不确定代码哪里出了问题,或者这个问题是否出在代码之外。 (使用 Xcode7 和 iPhone 4s 模拟器。)

编辑:这是用于转换为 UIImage 的代码。

- (UIImage *)filteredImageFromImage:(UIImage *)image andFilter:(CIFilter *)filter

{

    CIImage *unfilteredImage = [[CIImage alloc] initWithCGImage:image.CGImage];

    [filter setValue:unfilteredImage forKey:kCIInputImageKey];

    CIImage *filteredImage = [filter outputImage];

    CGRect extent = [filteredImage extent];

    CGImageRef cgImage = [self.context createCGImage:filteredImage fromRect:extent];

    UIImage *finalImage = [UIImage imageWithCGImage:cgImage];

    return finalImage;

}

最佳答案

使用 CIImage 时会出现此问题。但是当您显示图像时,它包含零值。因此,将您的 CIImage 转换为 UIImage。

例如

 CGImageRef image = [generator copyCGImageAtTime:time actualTime:&actualTime error:&err];

 UIImage *imageDisplay = [UIImage imageWithCGImage:image];

也许对你有帮助。

关于ios - 输入图像=零: Filtered Image not displaying?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33210614/

相关文章:

ios - Swift iOS 实时对视频应用滤镜?

ios - CIImage 将调整后的图像尺寸加倍

ios - 检测 iOS 11 设备上安装的证书

ios - 如何在 Cocoa 上使用 CIAffineTile?

ios - Realm - 将对象添加到另一个对象内的列表

android - 重置流以清除任何快照错误

ios - 在裁剪之前调整 UIImage 或 CIImage 的大小会拉伸(stretch)图像吗?

ios - 格式化数据 CIColorCube

ios - 全局创建显示警报功能并从任何 View Controller 调用它

ios - 如何更改 UICollectionViewCell 中 UILabel 的值?