views:

770

answers:

1

I've got a handle to a BITMAP structure (HBITMAP) in a Windows Mobile application -- I'd like to save the bitmap as a PNG file, using the IImage interface if possible. (There's no BMP file in this situation, the BITMAP is only in memory).

It looks like I could use IImagingFactory's IImagingFactory::CreateImageEncoderToFile method to save the file but I think I'd first have to get the BITMAP converted into "IImage" format.

Any ideas on how to do this with native code?

+1  A: 

Use CreateImageFromStream to read in your BITMAP data, that gives you an IImage.

Edit:

I did a little more research on this. There are a couple paths, but I think the easiest is to:

  1. create a DIBSECTION and blit your bitmap to it.
  2. Create a BitmapData instance pointing to the DIBSECTION for the image data.
  3. Call CreateBitmapFromBuffer to generate an IBitmapImage interface
  4. Push the IBitmapImage (which is an IImage) through your encoder.
ctacke
"Stream" in this case is a pointer to an IStream interface that provides the source data stream for the image -- how do you go from BITMAP data to that?
Ken
There's no need to create a DIBSECTION you can call GetObject on a hBitmap to get a pointer to bitmap bits. You can check in this thread for more detailed info http://social.msdn.microsoft.com/Forums/en-US/vssmartdevicesnative/thread/1d0f32d4-256b-4b03-91d6-1c487b638c63
Ismael