2013-11-21 40 views
0

如何从图像数据创建的base64字符串编码的base64编码的base64字符串, 生病尝试这样的Cocos2D-X - 从图像数据精灵或纹理数据

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

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