问题
Updated to Xcode 7 and getting this (warning?) message while an image was being rendered in an operation:
CreateWrappedSurface() failed for a dataprovider-backed CGImageRef.
There was no message like this under 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
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");
In this case I didn't get any console message, but had an assert: originalCIImage was nil.
The class reference of UIImage says:
@property(nonatomic, readonly) CIImage *CIImage
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");
The problem is, I'm still getting the warning messages in console.
Has anybody got this message before? What's the solution to nuke that warning(?) message?
Thanks, Adam
回答1:
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)
I noticed that the CGImageRef is dataprovider-backed with premultiplied values (RGB and A)
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".
I simply changed:
UIGraphicsBeginImageContextWithOptions(bounds, YES, 1.0f);
to
UIGraphicsBeginImageContextWithOptions(bounds, NO, 1.0f);
So that I am now creating a RGBA image, not an RGB image.
Now I convert my CGImage to CIImage and the CIImage NOW has proper dataprovider backing and the error goes away.
NOTE:
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.)
来源:https://stackoverflow.com/questions/32632085/getting-message-in-console-createwrappedsurface-failed-for-a-dataprovider-ba