kCGImageStatusUnknownType when calling CGImageSourceCreateWithDataProvider from UIGraphicsGetImageFromCurrentImageContext

StackOverflow https://stackoverflow.com/questions/14694718

Frage

I'm trying to create a CGImageSourceRef from a CGDataProviderRef. The CGDataProviderRef comes from a UIImage that was created with UIGraphicsGetImageFromCurrentImageContext. When I do this and check the status of my image source, it's returning kCGImageStatusUnknownType.

I've tried giving it a hint with kCGImageSourceTypeIdentifierHint but to no avail.

Does anyone know how I can create this CGImageSource?

Thanks!

War es hilfreich?

Lösung

You tell the source that you are giving it PNG data, but you are not. The data provider that you get from the CGImageGetDataProvider function provides raw pixel data, not data in some external format.

The purpose of a CGImageSource is to decode data in some external format (such as PNG) into CGImages. It can't handle pixel data; when you have pixel data, you can just create the CGImage from it directly. Of course, given that you already have the final image, I'm not sure why you're then trying to create it again from any kind of data at all.

If you want to generate some external data to subsequently (as in, after you release this image, possibly in another process) be loaded back in by a CGImageSource, use a CGImageDestination.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top