Thursday, February 17, 2011

How to convert BYTE* into a gdi+ image object?

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.

From stackoverflow
  • 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.

  • 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.

    : 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 comments:

Post a Comment