lemire/fastbase64

How to convert array of RGBA to base_64

PooyaEimandar opened this issue · 4 comments

Hi there
I have a uint8_t* which contains unpacked rgba data, my question is how to convert it to base_64?

int _width, _height, _comp;
uint8_t* _pixels = stbi_load("test.png", &_width, &_height, &_comp, 4);//4 for rgba
size_t _size = _width * _height * _comp;
char* _buffer = (char*)malloc(_size * 2);
size_t _expected = chromium_base64_encode(_buffer, reinterpret_cast<char*>(_pixels), _size);

this will not give me the right base64 encoded string.
Would you help me on this issue?
Thanks in advance.

*encoded

this will not give me the right base64 encrypted string.

How do you know?

(Note: it is not "encrypted" but "encoded". There is no cryptography involved.)

thanks for reply.

How do you know?

because my result(base64 image) does not show on browser. for example I used bing.base64 and it was ok.

because my result(base64 image) does not show on browser

Your browser can display certain image formats, like PNG or JPG. I don't think you can just dump some RGBA raw data in the HTML page and expect the browser to know what to do with it.

Try to encode a PNG file. Save it to disk, then load the bytes, and encode that.

@PooyaEimandar If you decode bing.base64, you'll see that it's a PNG image, not raw data.