Maximiliano Santa Cruz
Maximiliano Santa Cruz

Reputation: 401

C++: Convert base64 string into Image

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.

Upvotes: 3

Views: 16439

Answers (2)

Srijan Chaudhary
Srijan Chaudhary

Reputation: 697

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.

Upvotes: 0

Lee Louviere
Lee Louviere

Reputation: 5262

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.

Upvotes: 4

Related Questions