Download Base64 encoded image to Cocos2d-x

Q Cocos2d-xI am trying to load base64 encoded encoding to create a sprite. somewhere there seems to be an error because bool ok always returns false. Maybe someone 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);
+5
source share
1 answer

@MarkRansom answers an OP question:

I don't know anything about Cocos2DX, but I assume that the string you pass to base64Decode should be stripped of metadata in front.

+1
source

All Articles