Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
Giorgio is currently offline  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



Re: Encoding an image in base64 [message #57578 is a reply to message #57546] Sat, 02 October 2021 09:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 13442
Registered: November 2005
Ultimate Member
Try with Base64Encode instead please.

Encode64 is old "internal" format. Sorry about the confusion.

Mirek
Re: Encoding an image in base64 [message #57592 is a reply to message #57578] Mon, 04 October 2021 13:27 Go to previous message
Giorgio is currently offline  Giorgio
Messages: 218
Registered: August 2015
Experienced Member
That did the trick, thank you!
Previous Topic: Maximum images size in QTF
Next Topic: image viewer
Goto Forum:
  


Current Time: Mon Oct 25 16:19:36 CEST 2021

Total time taken to generate the page: 0.01467 seconds