【问题标题】:Cocos2d-x - encode base64 string from sprite or texture dataCocos2d-x - 从精灵或纹理数据中编码 base64 字符串
【发布时间】:2013-12-05 23:34:56
【问题描述】:

如何从图像数据创建base64字符串,从图像数据编码base64, 我试试这样

CCRenderTexture* r = CCRenderTexture::create(sprite->getTexture()->getPixelsWide(), sprite->getTexture()->getPixelsHigh());
r->beginWithClear(1, 1, 1, 0);
sprite->visit();
r->end();
CCImage *img = r->newCCImage();
unsigned char *data = img->getData();
int len = img->getDataLen();
str = base64_encode(data, len);


return str;

【问题讨论】:

    标签: c++ base64 cocos2d-x encode


    【解决方案1】:

    我找到了解决方案, 需要将图像读取为文本文件并在base64中解码, 我误解了工作img->getData();

    std::string str;
    unsigned long pSize = 0;
    unsigned char*filecont =  CCFileUtils::sharedFileUtils()->getFileData("file.png", "rb", &pSize);
    cout<<filecont;
    str = base64_encode(filecont, pSize);
    cout<<str;
    return str;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      相关资源
      最近更新 更多