【问题标题】:How can I get the contents of an std::string into a CFData object?如何将 std::string 的内容获取到 CFData 对象中?
【发布时间】:2010-09-21 21:12:40
【问题描述】:

我有一个function,它返回一个std::string 对象。我正在使用 Cocoa/CoreGraphics,我需要一种方法将该字符串中的数据获取到 CFData object 以便我可以将 that 输入到 CGDataProviderCreateWithCFData object 到制作一个CGImage

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

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

【问题讨论】:

    标签: c++ cocoa core-graphics cgimage cfdata


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-16
      • 2011-08-20
      相关资源
      最近更新 更多