2

I want to convert a BYTE* into an gdi+ Image object.

How can I do this?

The BYTE* seems a Dib point.

I found Image has a method named Image::FromStream() which may help, But I can not find any reference about how to convert a BYTE* into a IStream object. How can I do this?

Thanks in advance!

Actually, it is hard to believe MS provide a IStream interface, but do not provide any c++ MemoryStream class which implements the interface.

2
  • What language are you working in? Commented Nov 4, 2008 at 5:03
  • This thread solved this problem, please try this: [how-do-i-load-and-save-an-image-from-an-sql-server-database-using-gdi][1] [1]: stackoverflow.com/questions/192124/… Commented Jun 8, 2014 at 2:55

3 Answers 3

2

CreateStreamOnHGlobal will take an HGLOBAL and give you an IStream pointer. You'll need to allocate enough memory with GlobalAlloc, and then copy your BYTE array into the HGLOBAL.

If you know that the image data you've got is a GDI DIB, you can use GdipCreateBitmapFromGdiDib or the corresponding Bitmap::Bitmap constructor.

Sign up to request clarification or add additional context in comments.

1 Comment

Many thanks Roge, I opened the image successfully, and I find I was wrong the BYTE is not a Dib but a normal binary image file stream in JPG format. I opened it directly by FreeImage. Thanks.
0

Do you know the format of the image data the BYTE pointer points at? For Image to be able to construct itself from a stream, the data must be in one of the supported standard image formats (GIF, PNG, JPEG etc).

The IStream interface looks to be simple enough to implement on your own, if there's no suitable "memory stream" or similiar.

Comments

0

Using SHCreateMemStream,

IStream* stream = ::SHCreateMemStream({your BYTE array}, {size of the array});
Gdiplus::Image *img = Gdiplus::Image::FromStream(stream);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.