How can I get the contents of an std::string into a CFData object?

孤者浪人 提交于 2019-12-18 07:07:29

问题


I've got a function that returns a std::string object. I'm working with Cocoa/CoreGraphics and I need a way to get the data from that string into a CFData object so that I can feed that into a CGDataProviderCreateWithCFData object to make a CGImage.

The CreateCFData function wants a const UInt8* object (UInt8 being a typedef for unsigned char). The string represents the bytes from a decoded Base64 string (image data), so it appears to contain many null "characters" so the obvious casting of the .c_str() output to an unsigned char* object won't work.

I'm less experienced with C++ and very new to Cocoa/CoreGraphics, so if there's a much better way to accomplish what I'm wanting to do please let me know.


回答1:


CFDataCreate( NULL, (const UInt8*) myString.data(), myString.size() )



来源:https://stackoverflow.com/questions/3764512/how-can-i-get-the-contents-of-an-stdstring-into-a-cfdata-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!