简体   繁体   English

如何将CGImageRef转换为CGDataProviderRef?

[英]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. 我正在使用需要CGDataProviderRef的库,但是我知道如何从图像获取CGImageRef。

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 如何将imageRef转换为CGDataProviderRef

You don't. 你不知道

You use the CGDataProvider functions to create a CGDataProviderRef , then pass that to the library. 您可以使用CGDataProvider函数创建CGDataProviderRef ,然后将其传递给库。

See the CGDataProvider reference, and in particular: 请参阅CGDataProvider参考,尤其是:

CGDataProviderCreateWithCFData , CGDataProviderCreateWithData , CGDataProviderCreateWithFilename , CGDataProviderCreateWithCFDataCGDataProviderCreateWithDataCGDataProviderCreateWithFilename

CGDataProviderCreateWithURL

Have you tried not converting it to a `CGImageRef first? 您是否尝试过先将其转换为`CGImageRef? 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. 如果此方法不适用于您的情况,则可能在文档中指出了其他几种CGDataProviderCreateWithXXXXX方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM