How to show a base64 string on a component

Hi all, may app requests to server for getting some information, one of them is an image as a base64 string. Actually, How to show it on a component without saving the base64 string as image.
should do it for ya…

base64 string -> MemoryBlock::fromBase64Encoding() or Base64::convertFromBase64()
then feed that into ImageFileFormat::loadFrom(). if all goes well, you’ll get a juce::Image that you can draw in your component’s paint() call

void paint(Graphics& g) override
    g.drawImage( image );

Hi @matkatmusic
Why I created a base64 string then decoded it using Base64::convertFromBase64(), the function returned false. Here is my code:

MemoryOutputStream mo;
auto result = Base64::convertFromBase64(mo, gImageBase64);

The result is always false.
What wrong here? :frowning:
I tested the base64 string using this website

use ``` to format your code.

Also, look at the implementation of convertFromBase64 to see if you’re supposed to include the data:image/png;base64, part of your base64 string.

1 Like

Thank you @matkatmusic I can decode base64 now, just removed data:image/png;base64, from the string :slight_smile: