Strong Like Bull
Strong Like Bull

Reputation: 11317

How does one convert a CGImageRef to a CGDataProviderRef?

I am using a library that needs a CGDataProviderRef however I know how to get a CGImageRef from an image.

NSData* data = ... get raw image data from somewhere (PNG, JPEG, etc.) ...;
UIImage* image = [UIImage imageWithData: data];
CGImageRef imageRef = image.CGImage;

How do I convert imageRef to a CGDataProviderRef

Upvotes: 0

Views: 1331

Answers (2)

ondmike
ondmike

Reputation: 501

You don't.

You use the CGDataProvider functions to create a CGDataProviderRef, then pass that to the library.

See the CGDataProvider reference, and in particular:

CGDataProviderCreateWithCFData, CGDataProviderCreateWithData, CGDataProviderCreateWithFilename,

CGDataProviderCreateWithURL

Upvotes: 1

coneybeare
coneybeare

Reputation: 33101

Have you tried not converting it to a `CGImageRef first? From the docs

CGDataProviderRef CGDataProviderCreateWithData (
    void *info,
    const void *data,
    size_t size,
    CGDataProviderReleaseDataCallback releaseData
); 

If this method does not work for your situation, there are several other CGDataProviderCreateWithXXXXX methods pointed out in the docs which may.

Upvotes: 0

Related Questions