2013-11-21 43 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;