本文介绍了在控制台中获取消息:“CreateWrappedSurface() 对于数据提供者支持的 CGImageRef 失败."的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

已更新至 Xcode 7 并在操作中呈现图像时收到此(警告?)消息:

Updated to Xcode 7 and getting this (warning?) message while an image was being rendered in an operation:

CreateWrappedSurface() 对于数据提供者支持的 CGImageRef 失败.

在 Xcode 6.4 下没有这样的消息.

知道哪个代码部分抛出了消息:

Got which code part threw the message:

if (!self.originalImage) // @property (nonatomic, strong) UIImage *originalImage;
        return;

CGImageRef originalCGImage = self.originalImage.CGImage;
NSAssert(originalCGImage, @"Cannot get CGImage from original image");
CIImage *inputCoreImage = [CIImage imageWithCGImage:originalCGImage]; // this results the console message

我替换了我的 CIIImage 创建者以直接从 UIImage 获取它:

I replaced my CIIImage creator to get it directly from the UIImage:

CIImage *originalCIImage = self.originalImage.CIImage;
NSAssert(originalCIImage, @"Cannot build CIImage from original image");

在这种情况下,我没有收到任何控制台消息,但有一个断言:originalCIImage 为零.

In this case I didn't get any console message, but had an assert: originalCIImage was nil.

UIImage 的类引用说:

The class reference of UIImage says:

@property(nonatomic, readonly) CIImage *CIImage

如果 UIImage 对象是使用 CGImageRef 初始化的,则该属性的值为 nil.

If the UIImage object was initialized using a CGImageRef, the value of the property is nil.

所以我使用原始代码作为后备:

So I'm using the original code as fallback:

CIImage *originalCIImage = self.originalImage.CIImage;
if (!originalCIImage) {
    CGImageRef originalCGImageRef = self.originalImage.CGImage;
    NSAssert(originalCGImageRef, @"Unable to get CGimageRef of originalImage");
    originalCIImage = [CIImage imageWithCGImage:originalCGImageRef];
}
NSAssert(originalCIImage, @"Cannot build CIImage from original image");

问题是,我仍然在控制台中收到警告消息.

之前有人收到过这条消息吗?消除该警告(?)消息的解决方案是什么?

Has anybody got this message before? What's the solution to nuke that warning(?) message?

谢谢,亚当

推荐答案

终于想出了答案.对我研究 CIImage 工作原理的错误感到好奇 (https://uncorkedstudios.com/blog/image-filters-with-core-graphics)

Finally figured out the answer. Curious by the error I studied up on how CIImage works (https://uncorkedstudios.com/blog/image-filters-with-core-graphics)

我注意到 CGImageRef 是数据提供者支持的预乘值(RGB 和 A)

I noticed that the CGImageRef is dataprovider-backed with premultiplied values (RGB and A)

我想我正在加载到 CIImage 的 CGImage (使用 [CIImage imageWithCGImage:originalCGImage]; 只是 RGB 而不是 RGBA).果然,我是通过使用标准的 UIGraphicsBeginImageContextWithOptions 拍摄视图快照来创建此图像的,并且我将 opaque 参数设置为YES".

I thought to myself that the CGImage I am loading into a CIImage (using [CIImage imageWithCGImage:originalCGImage]; is only RGB and not RGBA). Sure enough, I was creating this image by taking a snapshot of a view using the standard UIGraphicsBeginImageContextWithOptions and I had the opaque parameter set to "YES".

我只是改变了:

UIGraphicsBeginImageContextWithOptions(bounds, YES, 1.0f);

UIGraphicsBeginImageContextWithOptions(bounds, NO, 1.0f);

所以我现在创建的是 RGBA 图像,而不是 RGB 图像.

So that I am now creating a RGBA image, not an RGB image.

现在我将我的 CGImage 转换为 CIImage 并且 CIImage 现在有适当的数据提供程序支持并且错误消失了.

Now I convert my CGImage to CIImage and the CIImage NOW has proper dataprovider backing and the error goes away.

我使用 CIClamp 过滤器进行高斯模糊处理,并且将 opaque 设置为 NO 时,钳位无法有效工作.我决定将不透明保持在 YES 并忽略日志警告,它们似乎实际上没有做任何事情.)

I was using a CIClamp filter for gaussian blur purposes, and with opaque set to NO the clamp doesn't work as effectively. I decided to just keep the opaque at YES and ignore the log warnings, they don't seem to actually do anything.)

这篇关于在控制台中获取消息:“CreateWrappedSurface() 对于数据提供者支持的 CGImageRef 失败."的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 01:34