The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: Ash_ on April 09, 2005, 10:47:31 AM

Title: Saving image from handle
Post by: Ash_ on April 09, 2005, 10:47:31 AM
if i have the handle (hwnd) to a control or a window i've painted and image onto. how do i get that image and save it to a file using the handle.

any tips or links would be appreciated. thanks in advance :)
Title: Re: Saving image from handle
Post by: thomasantony on April 09, 2005, 04:14:16 PM
Hi,
  If you painted the image, you probably have the image handle too. There must some way of making it into a file. No need of window handle. Unless you need to get the hDc of the window or something.

Thomas
Title: Re: Saving image from handle
Post by: Phoenix on April 09, 2005, 08:44:37 PM
It is possible using GDIplus.dll, if you like to have a look at it.. The way to do it is something like this:
(This does NOT work!)

Invoke GdipCreateFromHWND,hWnd,ADDR hGraphics
Invoke GetClientRect,hWnd,ADDR rct
Invoke GdipCreateBitmapFromGraphics,rct.right,rct.bottom,hGraphics,ADDR hBitmap
Invoke GdipGetImageEncodersSize,ADDR encoderNums,ADDR arraySize
**Need to allocate memory for encoders here
Invoke GdipGetImageEncoders,numEncoders,SIZE,ADDR encoders
Invoke GdipSaveImageToFile,hBitmap,ADDR szWFileName,clsidEncoder,encoderParams

The problem is to get the clsidEncoder, i did not try to do it in asm, but have a working function in VB6.
AFAIK, GDIplus supports saving as bmp-, png-, tiff-, jpg- and gif-formats. With VB6, i have tested png, bmp and gif.

Regards, phoenix