-1

I am new to FreeImage. I just want to read an JPEG image and display it in my MFC dialog. How do I do that? I try that using ImageStone by doing:

 img.Load(blob.data, size, IMG_JPG);
 img.Draw(hdc, DC);

Now, how do I do the same thing using FreeImage?

demongolem
  • 9,474
  • 36
  • 90
  • 105
Makoto
  • 1
  • 1
  • Since you are using MFC, why not go with [CImage](https://msdn.microsoft.com/en-us/library/bwea7by5.aspx) instead? No need to pull in another dependency. – IInspectable Jun 01 '17 at 17:43
  • I did not know that - Is it available in VS2013? – Makoto Jun 01 '17 at 17:46
  • [Yes](https://msdn.microsoft.com/en-us/library/bwea7by5(v=vs.120).aspx). – IInspectable Jun 01 '17 at 17:51
  • To load JPG, which CImage method do I use when I have JPG's blob data & size? – Makoto Jun 01 '17 at 18:38
  • [CImage::Load](https://msdn.microsoft.com/en-us/library/bwea7by5.aspx#cimage__load) has an overload to read from an [IStream](https://msdn.microsoft.com/en-us/library/windows/desktop/aa380034.aspx) interface. You can construct an `IStream` on a memory buffer using [SHCreateMemStream](https://msdn.microsoft.com/en-us/library/windows/desktop/bb773831.aspx). MFC may have pre-built wrapper classes as well. – IInspectable Jun 01 '17 at 18:50
  • I looked at SHCreateMemStream, but I do not know how my blob.data and nSize are used to create a stream? – Makoto Jun 01 '17 at 18:58
  • You have a pointer and a size. `SHCreateMemStream` takes a pointer and a size. – IInspectable Jun 01 '17 at 19:56

1 Answers1

0

I tried and it worked exactly the way you described.... I used SHCreateMemStream and fed the stream to the overloaded LOAD method of CImage. Everything worked perfectly.

Thank you so much, Makoto

CImage im;
IStream* is = SHCreateMemStream(Blob.pData, nSize);
HRESULT hr = im.Load(is);
RECT rect = { 0, 0, 500, 500 };
BOOL b = im.Draw(hdc, rect);
Makoto
  • 1
  • 1
  • The answer space should just be for a solution. You can edit your answer to show what you explicitly did. – quantik Jun 01 '17 at 20:11
  • This does not answer the question (*"How to read jpg using FreeImage"*). While this is the solution *you* were looking for, it is not a solution in general. If you want to persist this answer, you should ask a new question, asking about your **real** problem (*"How to read jpg data from an MFC application"*), and answer that. Besides, the code is leaking an `IStream` object. – IInspectable Jun 02 '17 at 08:22