Reputation: 145
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);
Upvotes: 5
Views: 2100
Reputation: 27155
@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.
Upvotes: 1