如何将 std::string 的内容获取到 CFData 对象中?

发布于 2024-09-24 13:04:06 字数 868 浏览 0 评论 0原文

我有一个 函数 返回一个 std: :string 对象。我正在使用 Cocoa/CoreGraphics,我需要一种方法将该字符串中的数据获取到 CFData 对象,以便我可以将输入CGDataProviderCreateWithCFData < a href="https://stackoverflow.com/questions/2261177/cgimage-from-byte-array/2261343#2261343">对象来制作CGImage

CreateCFData 函数需要一个 const UInt8* 对象(UInt8unsigned char 的 typedef)。该字符串表示解码的 Base64 字符串(图像数据)中的字节,因此它似乎包含许多空“字符”,因此 .c_str() 输出明显转换为 unsigned char * 对象将不起作用。

我对 C++ 的经验较少,而且对 Cocoa/CoreGraphics 很陌生,所以如果有更好的方法来完成我想做的事情,请告诉我。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

英雄似剑 2024-10-01 13:04:06

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文