Cannot get bitmaps of screen from Gdip

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SuperMrTheGuy1

Cannot get bitmaps of screen from Gdip

04 Apr 2017, 00:38

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
User avatar
JoeWinograd
Posts: 2214
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Cannot get bitmaps of screen from Gdip

04 Apr 2017, 00:56

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?
SuperMrTheGuy1

Re: Cannot get bitmaps of screen from Gdip

04 Apr 2017, 01:05

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

Re: Cannot get bitmaps of screen from Gdip

04 Apr 2017, 01:08

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.
User avatar
JoeWinograd
Posts: 2214
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Cannot get bitmaps of screen from Gdip

04 Apr 2017, 02:02

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

Re: Cannot get bitmaps of screen from Gdip

04 Apr 2017, 19:49

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
just me
Posts: 9576
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Cannot get bitmaps of screen from Gdip

05 Apr 2017, 01:51

Are you running AHK x64? The original Gdip lib is not completely x64 compatible.
SuperMrTheGuy1

Re: Cannot get bitmaps of screen from Gdip

05 Apr 2017, 20:23

That fixed it! I was using x64 installation and not x32 installation. Wasted about 10 hours on this thank you so much!
User avatar
JoeWinograd
Posts: 2214
Joined: 10 Feb 2014, 20:00
Location: U.S. Central Time Zone

Re: Cannot get bitmaps of screen from Gdip

05 Apr 2017, 22:09

Great catch, just me!
ed1chandler
Posts: 15
Joined: 15 May 2015, 11:18

Re: Cannot get bitmaps of screen from Gdip

21 Apr 2017, 14:44

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.
iseahound
Posts: 1472
Joined: 13 Aug 2016, 21:04
Contact:

Re: Cannot get bitmaps of screen from Gdip

21 Apr 2017, 23:22

Use Gdip_All which is 32 and 64 bit compatible.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: mikeyww, peter_ahk, Spawnova and 343 guests