SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
Posted: 04 Sep 2019, 13:54
by SKAN
SavePicture( hBM, sFile )
Note: This function offers limited functionality: JPEG quality is fixed at 75% and transparency will not be preserved for PNG.
Saved file will be a BMP if you pass any file extension other than: BMP, JPG, JPEG, GIF, PNG, TIF, TIFF
1 : OK
0 : Invalid hBitmap
-1 : GDI+ not initialised. Call GDIP("Startup") to init.
-2 : Invalid (save) filepath or no write access to destination path.
-3 : GdipDisposeImage() failed. Less likely to occur.
SavePicture() requires GDI+ initialized prior to calling it.
GDI+ can be Start.Shut with GDIP("Startup") and GDIP("Shutdown") Thanks to @tmplinshi for a bug report. Now fixed.
I'm breaking the ID to 4 UINTs and encoding them with nested NumPut().
The first UINT is 0x557CF400 for BMP and it increments by 1 for other image types.
The rest of UINTs are same for all image types.
I check the save file path extension and add the appropriated value to this UINT before encoding it.
The following script will automatically Save picture (JPEG) when PrintScreen / Alt+PrintScreen is used for screen capture.
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
Posted: 07 Sep 2019, 03:11
by SKAN
Thank you @tmplinshi
Fixed.
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
Posted: 03 Jan 2020, 09:41
by danrevella
Hi,
please excuse for boring, I have look at your tool (and also another in fact this post is replicate over), but I am in search of a script who let me capture and save a full windows who is larger then my desktop: f.e my desktop is 1920*1080 but the window I need to capture is 9400*9200, so if i use PrintScreen or Alt-Printscreen, I obtain an image who only show 1920*1080 instead of 9400*9200.
Does exist a possibility to get the full capture window?
Many thanks
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
f.e my desktop is 1920*1080 but the window I need to capture is 9400*9200
I don't understand how this is possible?
If I try to resize a given window to be larger than desktop, the window is resized only to the size of desktop.
For example, with single monitor setup sized 1366x768, I am not able to resize notepad window to 6000x4000 ?!
#t::
WinGet, window, ID, A
InputBox, width, Resize window, Enter width:, , 170, 130
if (width != "")
{
InputBox, height, Resize Window, Enter height:, , 170, 130
}
WinGetTitle, Title, A
MsgBox, The active window is "%Title%".
It is possible: try this an give any resolution you want to a (resizable) window
Thanks. Nice test code. Nitpick: You haven't defined the constant HWND_TOP which should be 0.
Your snippet doesn't work for all apps though. Maybe those apps have message handlers to override the resize.
Works when tested with Notepad and AutoHotkey help. AutoHotkey spy reveals the window size correctly.
I tried resizing AutoHotkey help to 2000x2000 (My screen is 1366x768) and took a snaphot with hBM := hWnd_to_hBmp( WinExist("A") )
and saved it with SavePicture().
The function is unable to blit the title bar correctly, in Windows 7. Yet to try in Windows 10.
Please refer the attachment
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
#t::
WinGet, window, ID, A
InputBox, width, Resize window, Enter width:, , 170, 130
if (width != "")
{
InputBox, height, Resize Window, Enter height:, , 170, 130
}
WinGetTitle, Title, A
MsgBox, The active window is "%Title%".
It is possible: try this an give any resolution you want to a (resizable) window
Thanks. Nice test code. Nitpick: You haven't defined the constant HWND_TOP which should be 0.
Your snippet doesn't work for all apps though. Maybe those apps have message handlers to override the resize.
Works when tested with Notepad and AutoHotkey help. AutoHotkey spy reveals the window size correctly.
I tried resizing AutoHotkey help to 2000x2000 (My screen is 1366x768) and took a snaphot with hBM := hWnd_to_hBmp( WinExist("A") )
and saved it with SavePicture().
The function is unable to blit the title bar correctly, in Windows 7. Yet to try in Windows 10.
Please refer the attachment
As I told you, I'm a total beginner in AHK, so please may you post your example with a full working code (also with the necessary dependences?
Many thanks
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
does not work for me. i tried resizing notepad to 9000 width, and it only resized to approx 4800 width, which spanned my two monitors.
you could try PrintWindow() to get the screenshot
As I told I'm a newbie, may you gentle tell me about PrintWindow(), is it a native function, or is it a library, may you be so kind to give me the necessary code?
Thanks
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
Posted: 04 Jan 2020, 03:04
by SKAN
I have to test this in Windows 10.
I'm leaving city and will be back on Monday.
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
Posted: 04 Jan 2020, 05:48
by danrevella
you told me:
Thanks. Nice test code. Nitpick: You haven't defined the constant HWND_TOP which should be 0.
So may you give me the correction to my code?
See you next week
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
Posted: 22 Feb 2022, 01:52
by jly
Hello, SKAN:
I get the thumbnail of a file as an HBitmap, add it to a Picture control, and the background of the picture is transparent.
If I save it as a .png file with SavePicture functtion, the background of the image file is black.
How can I make the background of the saved picture transparent?
In the following two figures, the first is the image of the saved png file,
and the second is the image displayed in the picture control.
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
If I save it as a .png file with SavePicture functtion, the background of the image file is black.
Yes. This function is compact and too limited, and I have mentioned it in OP.
If you need to save PNG with transparency, you may have to opt for one of the GDIP variants available in our forum.
Thanks.
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
If I save it as a .png file with SavePicture functtion, the background of the image file is black.
Yes. This function is compact and too limited, and I have mentioned it in OP.
If you need to save PNG with transparency, you may have to opt for one of the GDIP variants available in our forum.
Thanks.
OK,thank you very much!
Re: SavePicture() : Save hBitmap as BMP, JPG, GIF, PNG, TIF
Note: This function offers limited functionality: JPEG quality is fixed at 75% and transparency will not be preserved for PNG.
Saved file will be a BMP if you pass any file extension other than: BMP, JPG, JPEG, GIF, PNG, TIF, TIFF
1 : OK
0 : Invalid hBitmap
-1 : GDI+ not initialised. Call GDIP("Startup") to init.
-2 : Invalid (save) filepath or no write access to destination path.
-3 : GdipDisposeImage() failed. Less likely to occur.
SavePicture() requires GDI+ initialized prior to calling it.
GDI+ can be Start.Shut with GDIP("Startup") and GDIP("Shutdown") Thanks to @tmplinshi for a bug report. Now fixed.
I'm breaking the ID to 4 UINTs and encoding them with nested NumPut().
The first UINT is 0x557CF400 for BMP and it increments by 1 for other image types.
The rest of UINTs are same for all image types.
I check the save file path extension and add the appropriated value to this UINT before encoding it.
The following script will automatically Save picture (JPEG) when PrintScreen / Alt+PrintScreen is used for screen capture.