 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Xander
Joined: 23 Sep 2007 Posts: 140
|
Posted: Wed Oct 24, 2007 4:31 am Post subject: In-memory Window Capture |
|
|
The following script allows you to create a capture of a window in memory and read information from that window as opposed to reading it from the screen. Reading from the screen is not only unreliable (overlapping windows) but it is also slower. Also, the window doesn't need to be visible in order to get a capture of it, but it cannot be minimized.
Download: Display.ahk
Functions in v0.1:
| Code: | Display_CreateWindowCapture(device, context, pixels [, id])
Display_DeleteWindowCapture(device, context, pixels)
Display_GetPixel(context, x, y)
Display_PixelSearch(x, y, w, h, color, variation [, id])
Display_FindPixelHorizontal(x, y, w, h, color, variation, context)
Display_FindPixelVertical(x, y, w, h, color, variation, context)
Display_FindText(x, y, w, h, color, variation, context) |
And other functions mainly for internal useage.
Also provided is a shell function to read text (Display_ReadArea), but it is without any mappings. Therefore it won't read anything as-is (you must provide the mappings).
| Code: | | Display_ReadArea(x, y, w, h, color, variation, id, maxwidth, exclude) |
Also, besides specifying colors in BGR format, you can also use any of the following:
| Code: | BlueBackground, BlueForeground, GreenBackground, GreenForeground, RedBackground, RedForeground
CyanBackground, CyanForeground, YellowBackground, YellowForeground, VioletBackground, VioletForeground
DarkBackground, DarkForeground, LightBackground, LightForeground |
|
|
| Back to top |
|
 |
BoBoĻ Guest
|
Posted: Wed Oct 24, 2007 5:59 am Post subject: |
|
|
Sounds promising.
Would you mind to advise the crowd that you've commented the script in detail within the code. That might be of help/interest for those who won't be able to catch its concept on-the-fly.
Thx for listening & for sharing it.
Keep things going.
 |
|
| Back to top |
|
 |
HuBa
Joined: 24 Feb 2007 Posts: 172 Location: Budapest, Hungary
|
Posted: Wed Oct 24, 2007 1:18 pm Post subject: |
|
|
Really promising!
I haven't tested it yet but it looks like it can capture frames from a webcam or any other video source too. Or maybe from another user session.
But as I see you save the bitmap pixel-by-pixel so it is not a fast one. |
|
| Back to top |
|
 |
Xander
Joined: 23 Sep 2007 Posts: 140
|
Posted: Wed Oct 24, 2007 3:32 pm Post subject: |
|
|
| BoBoĻ wrote: |
Would you mind to advise the crowd that you've commented the script in detail within the code. That might be of help/interest for those who won't be able to catch its concept on-the-fly. |
Ahh yes, I forgot to mention that the details of which each function does, as well as well as a description of each parameter is in the source code.
Now it should be know  |
|
| Back to top |
|
 |
Xander
Joined: 23 Sep 2007 Posts: 140
|
Posted: Wed Oct 24, 2007 3:36 pm Post subject: |
|
|
| HuBa wrote: | | I haven't tested it yet but it looks like it can capture frames from a webcam or any other video source too. | I haven't really tested it much other than normal application windows that I use it for so I don't know if that will work or not.
| HuBa wrote: | | But as I see you save the bitmap pixel-by-pixel so it is not a fast one. | This script doesn't "save" anything, it just creates an image of a window in memory from which information can be obtained. I use it to test if a button is in a certain state or is visible and whatnot as well as to read numbers from a window that can otherwise not be obtained (window paints its own buttons or text etc...)
The Display_ReadArea function was 5x faster when using the window capture method as opposed to reading the pixels directy from the screen... |
|
| Back to top |
|
 |
Ile Guest
|
Posted: Sun Jan 27, 2008 7:09 pm Post subject: Re: In-memory Window Capture |
|
|
| Xander wrote: |
| Code: | | Display_ReadArea(x, y, w, h, color, variation, id, maxwidth, exclude) |
|
Does this read any text or just the characters "$.,0123456789"?
If just those characters, is there a way to make it read normal text (a-z) as well?
Thanks. |
|
| Back to top |
|
 |
thewer
Joined: 12 Feb 2008 Posts: 5 Location: Munich, Germany
|
Posted: Wed Feb 27, 2008 10:42 am Post subject: |
|
|
Hi there,
Thanks for your code - it really helped me understanding a lot of things about GDI...
Still I got some problems with it -
what I'm trying to do:
I want to make screenshots of a certain window every ** minutes and save these images as *.png.
This kind of works, except:
- The code I'm using doesn't make a shot of the actual window, but of the desktop at the window coordinates. So if this window isn't the top/active one, the images I get are from the windows overlapping the one I want.
- Sometimes the screen area seems to be messed up - although I'm giving the right coordinates (nL, nT, nW, nH), they sometimes(!) don't seem to fit...
I think my problem either lies in the definition of hDC or mDC, not sure so...
I also tried to create the hBM not as CompatibleBitmap but as CreateDIBSection, but the result is absolutely the same, CreateCompatibleBitmap just seems to be the easieer way. Instead of your "PrintWindow" I'm using "BitBlt" as shown in this thread (http://www.autohotkey.com/forum/topic18146.html) to copy the color values - this could of course be the reason for mixing up coordinates, but I looked all commands up in the MS GDI help, and it seems to be used the right way...
I know the window doesn't have to be minimized, but I thought just being in the back should work (another funny bug is, when part of the window is off the screen - then the image is all black).
Sorry for bothering, just can't figure it out on my own...
Thanks for your help!
| Code: | {
if !id
WinGet, id, ID
hDC := DllCall("GetDC", UInt, id)
WinGetPos, nL, nT, nW, nH, ahk_id %id%
WinGetTitle, this_title, ahk_id %id%
mDC := DllCall("gdi32.dll\CreateCompatibleDC", "Uint", hDC)
hBM := DllCall( "gdi32.dll\CreateCompatibleBitmap" , "uint", hDC, "int", nW, "int", nH )
DllCall("gdi32.dll\SelectObject", "Uint", mDC, "Uint", hBM)
DllCall("BitBlt", "Uint", mDC, "int", 0, "int", 0, "int", nW, "int", nH, "Uint", hDC, "int", nL, "int", nT, "Uint", 0x40000000 | 0x00CC0020)
sFile = %this_title%_%time%.png
Convert(hBM, sFile) ;Function for saving image as png
DllCall("ReleaseDC", "Uint", 0, "Uint", hDC)
DllCall("DeleteDC", "Uint", mDC)
DllCall("DeleteObject", "Uint", hBM)
} |
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|