如何获取std :: string的内容到CFData对象? [英] How can I get the contents of an std::string into a CFData object?
问题描述
我有一个函数返回 std :: string
对象。我正在使用Cocoa / CoreGraphics,我需要一种方法来从该字符串中获取数据到 CFData
对象,以便我可以将 提供给 CGDataProviderCreateWithCFData
对象使 CGImage
。
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
.
CreateCFData
函数需要一个 const UInt8 *
( UInt8
是 unsigned char
的typedef)。该字符串表示来自解码的Base64字符串(图像数据)的字节,因此它看起来包含许多空字符,所以明显转换 .c_str()
输出到 unsigned char *
对象将无法工作。
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.
我对C ++的经验不多, / CoreGraphics,所以如果有一个更好的方法来完成我想做的,请让我知道。
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.
推荐答案
code> CFDataCreate(NULL,(const UInt8 *)myString.data(),myString.size())
CFDataCreate( NULL, (const UInt8*) myString.data(), myString.size() )
这篇关于如何获取std :: string的内容到CFData对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!