In Cocos2d-x
I am trying to load a base64 encoded image string to create a sprite. somewhere there seems to be a mistake though because bool ok always returns false. Maybe anybody can help me?
Here is the code I'm using:
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 answers the OP's question:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With