Cocos2d-x - 从精灵或纹理数据中编码base64字符串

时间:2013-11-21 13:13:16

标签: c++ base64 cocos2d-x encode

如何从图像数据创建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;

1 个答案:

答案 0 :(得分:0)

我找到了解决方案, 需要将图像作为文本文件读取并在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;