I am having difficulty using Gdip to get bitmaps of windows given a window handle. I have tried using a basic script that was actually provided by another user on this forum, as seen from the link below, but the Gdip_BitmapFromScreen() returns nothing.
https://autohotkey.com/board/topic/9142 ... of-screen/
This is the code that I have tried, pToken is 928019671, and the bitmap is blank and does not save a bitmap to disk.
If you could help me at all, thanks!
F1::
pToken := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen()
Gdip_SaveBitmapToFile(pBitmap, "Image.png")
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
msgbox %pToken% %pBitmap%
Return
Cannot get bitmaps of screen from Gdip
- JoeWinograd
- Posts: 2214
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Cannot get bitmaps of screen from Gdip
The code you posted works perfectly here – creates a file called Image.png in the folder where the script is. Have you included the Gdip code in your script or an #Include statement for it?
Re: Cannot get bitmaps of screen from Gdip
I have included the Gdip.ahk file in my code, i have this line in it:
#include Gdip.ahk ; download form http://www.autohotkey.com/forum/topic32238.html
Also the Gdip.ahk is in the same directory as the script is running from.
#include Gdip.ahk ; download form http://www.autohotkey.com/forum/topic32238.html
Also the Gdip.ahk is in the same directory as the script is running from.
Re: Cannot get bitmaps of screen from Gdip
I have included the Gdip.ahk in my script, using the following line which is near the beginning of the script:
#include Gdip.ahk ; download form http://www.autohotkey.com/forum/topic32238.html
I have also created a file called Gdip.ahk in the same directory as the script which includes the Gdip download.
#include Gdip.ahk ; download form http://www.autohotkey.com/forum/topic32238.html
I have also created a file called Gdip.ahk in the same directory as the script which includes the Gdip download.
- JoeWinograd
- Posts: 2214
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Cannot get bitmaps of screen from Gdip
Are you using the code at this link:
http://www.autohotkey.net/~tic/Gdip.ahk
That's what I'm using and the script you posted works perfectly with it (AHK 1.1.25.01/U32). The first troubleshooting step I would take is to put in a simple MsgBox command after each of your first three Gdip function calls to show what the functions are returning. My guess is that the Gdip_SaveBitmapToFile call is returning something other than zero — the error values (-1 through -5) are documented in the Gdip source.
http://www.autohotkey.net/~tic/Gdip.ahk
That's what I'm using and the script you posted works perfectly with it (AHK 1.1.25.01/U32). The first troubleshooting step I would take is to put in a simple MsgBox command after each of your first three Gdip function calls to show what the functions are returning. My guess is that the Gdip_SaveBitmapToFile call is returning something other than zero — the error values (-1 through -5) are documented in the Gdip source.
Re: Cannot get bitmaps of screen from Gdip
I have changed the code so that it is the following code at the end, and still am having issues.
The ptoken value is 949203328, which I assume is ok.
pBitmap returns 0, which from reading the man pages I think is a pointer to a bitmap image, which worries me that it is 0.
Then SavebitmapToFile fails and the error code is -3, which is "Could not find matching encoder for specified file format".
I am unsure of how to proceed from this point, could I be missing additional drivers necessary?
#include Gdip.ahk ; download form http://www.autohotkey.com/forum/topic32238.html
F1::
pToken := Gdip_Startup()
msgbox ptoken %pToken%
pBitmap := Gdip_BitmapFromScreen()
msgbox pBitmap %pBitmap%
statusofsave := Gdip_SaveBitmapToFile(pBitmap, "Image.bmp")
msgbox save status %statusofsave%
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
Return
The ptoken value is 949203328, which I assume is ok.
pBitmap returns 0, which from reading the man pages I think is a pointer to a bitmap image, which worries me that it is 0.
Then SavebitmapToFile fails and the error code is -3, which is "Could not find matching encoder for specified file format".
I am unsure of how to proceed from this point, could I be missing additional drivers necessary?
#include Gdip.ahk ; download form http://www.autohotkey.com/forum/topic32238.html
F1::
pToken := Gdip_Startup()
msgbox ptoken %pToken%
pBitmap := Gdip_BitmapFromScreen()
msgbox pBitmap %pBitmap%
statusofsave := Gdip_SaveBitmapToFile(pBitmap, "Image.bmp")
msgbox save status %statusofsave%
Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)
Return
Re: Cannot get bitmaps of screen from Gdip
Are you running AHK x64? The original Gdip lib is not completely x64 compatible.
Re: Cannot get bitmaps of screen from Gdip
That fixed it! I was using x64 installation and not x32 installation. Wasted about 10 hours on this thank you so much!
- JoeWinograd
- Posts: 2214
- Joined: 10 Feb 2014, 20:00
- Location: U.S. Central Time Zone
Re: Cannot get bitmaps of screen from Gdip
Great catch, just me!
-
- Posts: 15
- Joined: 15 May 2015, 11:18
Re: Cannot get bitmaps of screen from Gdip
Ugh, wasted a few hours on that myself. It worked perfectly while debugging in Scite (which apparently uses the 32-bit version), but wouldn't do squat when I just double-clicked the script.
My solution (and someone please tell me a better one) is to change the extension of scripts requiring the 32-bit version to ".ahk32" and then associate that extension with AutohotkeyU32.exe.
THANK YOU for pointing this out.
My solution (and someone please tell me a better one) is to change the extension of scripts requiring the 32-bit version to ".ahk32" and then associate that extension with AutohotkeyU32.exe.
THANK YOU for pointing this out.
Re: Cannot get bitmaps of screen from Gdip
Use Gdip_All which is 32 and 64 bit compatible.