如何获取std :: string的内容到CFData对象? [英] How can I get the contents of an std::string into a CFData object?

查看:242
本文介绍了如何获取std :: string的内容到CFData对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个函数,返回 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆