Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Encoding an image in base64
Encoding an image in base64 [message #57546] |
Sun, 19 September 2021 13:34  |
Giorgio
Messages: 218 Registered: August 2015
|
Experienced Member |
|
|
Hi there,
I have a RichText field that contains some formatted text that I need to convert it to a base64 encoded PNG image.
I've been trying to use PNGEncoder and Encode64() with mixed results:
RichText text;
//text is filled in
ImagePainter w(3000, 100);
w.DrawRect(0, 0, 3000, 100, White());
text.Paint(w, 0, 0, 3000);
PNGEncoder png;
png.SaveFile("C:\\Temp\\richtext.png", w);
The above code works perfectly: I got a PNG image that can be viewed with any image viewer.
Anyway, I need the image to be encoded in base64, so I change the "png.SaveFile()" line above with the following:
String png_string = png.SaveString(w);
SaveFile("C:\\Temp\\test.txt",Encode64(png_string));
If I open the txt file, copy the content and paste it into an online base64 decoder (I tried a few) the image cannot be decoded.
What I do wrong?
Thankks,
gio
|
|
|
|
|
Goto Forum:
Current Time: Mon May 29 22:58:13 CEST 2023
Total time taken to generate the page: 0.01214 seconds
|