This is a class that makes using GDI to accelerate pixel detection nice and easy.
It works by introducing the concept of a "Snapshot". A Snapshot is a copy of the portion of the screen stored in memory that you can query using a command that works like AHK's PixelGetColor.
One advantage of this technique is that you are taking a copy of a portion of the screen at a single point in time, so you do not have to worry about the screen changing part way through making multiple pixel checks.
ie, it makes it easy to perform multiple checks on one "frame" of the stream of images.
Also, when you check a pixel color from the snapshot, the result is cached, meaning faster results if you check that pixel's color in the future - so no need to worry about storing local copies of pixel colors to speed up processing.
What are the features / How do I use it?
Using the class is a Snap (ahem).
Define the Snapshot area as a 200x200 block of the screen at coordinates 300,300:
Code: Select all
#include <CGdipSnapshot>
snap := new CGdipSnapshot(300,300,200,200) ; x, y, width, height
snap.TakeSnapshot()
Some time later.... We can still inspect this snapshot, even if the screen has changed.
Sleep 999999
Pixel values can be read as Hex or r/g/b values.
You can use coordinates relative to the Screen or the Snapshot.
Code: Select all
hex_value:= snap.PixelGetColor(300,300).rgb
= 0xFF0000
r_value := snap.SnapshotGetColor(0,0).r
= 255
Code: Select all
myval := snap.PixelScreen[300,300].rgb
myval := snap.PixelScreen[300,300].rgb ; no DLL call!
myval := snap.PixelSnap[0,0].rgb ; Same value, still no DLL call!
bool := snap.PixelScreen[300,300].Compare(snap.PixelScreen[0,0]) ; this will always be true, and only ever require one DLL call!
Use multiple snapshots at one time! Easily compare!
Code: Select all
snap1 := new CGdipSnapshot(300,300,200,200)
snap2 := new CGdipSnapshot(300,300,200,200)
snap1.TakeSnapshot()
Sleep 5000
snap2.TakeSnapshot()
if (snap1.PixelSnap[0,0].Compare(snap2.PixelSnap[0,0])){
msgbox % "Pixel 0,0 did not change for 5 seconds"
}
if (snap1.Compare(snap2)){
msgbox % "Snapshot 1 and 2 are similar"
}
Just create a Text box with attribute 0xE and store the HWND, then call the function:
Code: Select all
Gui, Add, Text, 0xE x5 y5 w%w% h%h% hwndSnapshotPreview
snap.ShowSnapshot(SnapshotPreview)
snap.SaveSnapshot("myfile.png")
Where can I get it?
Requires the gdip_all library from here
GitHub Page (Download from here)
Wiki - Full Documentation
Full example script