简体   繁体   English

Cocos2d-x-从Sprite或Texture数据编码base64字符串

[英]Cocos2d-x - encode base64 string from sprite or texture data

How create base64 string from image data, encode base64 from image data, Ill try like this 如何从图像数据创建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;

I found the solution, Need to read the image as a text file and decode in base64, I misunderstood about the work img-> getData (); 我找到了解决方案,需要将图像读取为文本文件并在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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM