gylns gylns - 1 month ago 11x
C++ Question

How to use GDI+ library to decode a jpeg in memory?

GDI+ provides a Image class, and you can use this class to read a image file with one format and then save this file to another format. But if I want to just decode a jpeg file (already loaded into memory), how can I do it?


You can use SHCreateMemStream

IStream* stream = SHCreateMemStream(buf, bufsize);
Gdiplus::Image *image = Gdiplus::Image::FromStream(stream);

Gdiplus::Graphics g(hdc);

Where buf contains jpeg data (or any other compatible image format) and bufsize is the length of that data.

SHCreateMemStream needs "Shlwapi.lib" library.