I have an application that is currently written in C # that can take a Base64 encoded string and turn it into an image (a TIFF image in this case) and vice versa. In C #, this is actually quite simple.
private byte[] ImageToByteArray(Image img) { MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Tiff); return ms.ToArray(); } private Image byteArrayToImage(byte[] byteArrayIn) { MemoryStream ms = new MemoryStream(byteArrayIn); BinaryWriter bw = new BinaryWriter(ms); bw.Write(byteArrayIn); Image returnImage = Image.FromStream(ms, true, false); return returnImage; }
(and, now that I look at it, it can be simplified)
Now I have a business need to do this in C ++. I use GDI + for drawing graphics (only up to Windows), and I already have code for decode a string in C ++ (for another string). However, I stumble upon getting information into an Image object in GDI +.
At this point, I believe that I need
a) A way to convert this Base64-decoded string to an IStream to feed to an Image FromStream object
b) A way to convert a Base64 encoded string to IStream to feed a FromStream object to the Image object (so thereโs a different code than I'm using now)
c) Some completely different ways that I don't think about.
My C ++ skills are very rusty and I am also spoiled by the managed .NET platform, so if I am on this incorrectly, I am open to suggestions.
UPDATE: In addition to the solution I posted below, I also figured out how to go the other way , if anyone needs it.
source share