Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading Base64 encoded Image in Cocos2d-x

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);
like image 805
aushilfe444 Avatar asked Nov 13 '22 08:11

aushilfe444


1 Answers

@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.

like image 133
Quuxplusone Avatar answered Nov 14 '22 22:11

Quuxplusone