在 Cocos2d-x
中,我试图加载一个 base64 编码的图像字符串来创建一个 Sprite 。某处似乎有错误,因为 bool ok 总是返回 false。也许有人可以帮助我?
这是我使用的代码:
std::string source = "data:image/png;base64,iVBORw0K....."
int len = 0;
unsigned char *buffer;
len = base64Decode((unsigned char*)source.c_str(), (unsigned int)source.length(), &buffer);
CCImage* img = new CCImage();
bool ok = img->initWithImageData(buffer,len);
最佳答案
@MarkRansom 回答了 OP 的问题:
I don't know anything about Cocos2DX but I'm guessing the string you pass to base64Decode needs to be stripped of the meta-data at the front.
关于android - 在 Cocos2d-x 中加载 Base64 编码的图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15551657/