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