3

is there some way to convert a base64 string into an image; in Visual C++? I got an image as a result of getting the image from an url, encoded as a base64 so, I need to get it back.

I'm really lost in this matter; I'm using Visual C++ 2010.

So far I've been digging about GDI+ but I don't know if it is correct.

Thanks.

2 Answers2

4

Convert into bytes, convert bytes into bitmap, (optional) bitblt bitmap onto window.

How do I base64 encode (decode) in C?

How can I create an Image in GDI+ from a Base64-Encoded string in C++?

You need to know what type of image the resulting bytes are. Then you need to find an algorithm that can understand that, or just save the bytes as a file type (if it is already built with header info and everything).

If it's just a bitmap (like a MFC bitmap), you'll need a way to convert that into an image, if you intend to save it. If you just intend to display it and it's already a bitmap, then just use the GDI methods.

Community
  • 1
  • 1
Lee Louviere
  • 5,162
  • 30
  • 54
  • Hello, I followed this link http://stackoverflow.com/questions/2746855/how-can-i-create-an-image-in-gdi-from-a-base64-encoded-string-in-c and worked. Thank you. – Maximiliano Santa Cruz Dec 06 '11 at 18:38
0

Boost is a great set of libraries when it comes C++ and it's documentation can be found here.

So we have a encode and decode supported by Boost.

A more detailed implementation of Boost Base64 encode-decode can be found here.

Another useful library is of Microsoft CPPRESTSDK, also known as Casablanca project. Under this they have defined a utility::conversion namespace which deals with all different type of encoding-decoding which one can come across while developing an API. Among this from_base64 (const utility::string_t &str), which can be used to decode the given base64 string to a byte array.

Srijan Chaudhary
  • 637
  • 1
  • 8
  • 18