I understand that for some things it would be better to write certain things in C++, but I'd really like to be able to do this in AHK:
I want to be able to retrieve the pixel data from a 100x300 area of the screen, however PixelGetColor
is way too slow. Here's a test demonstrating that it takes about 0.02 seconds per pixel, which is roughly 11.5 hours to get the pixel data from an entire 1920 x 1080 screen.
In the test, it'll take about 4-5 seconds just to get the pixel data from a 15 x 15 area of the screen.
width := 15 ; 1920
height := 15 ; 1080
searchResolution := 1 ; 3
columns := width / searchResolution
rows := height / searchResolution
resultRows := {}
columnCounter := 0
rowCounter := 0
resultCounter := 0
start := getTimestamp()
loop, %columns%
{
resultRows[columnCounter] := {}
loop, %rows%
{
PixelGetColor, pixelColor, columnCounter, rowCounter
resultRows[columnCounter][rowCounter] := pixelColor
rowCounter += searchResolution
resultCounter += 1
}
columnCounter += searchResolution
rowCounter := 0
}
end := getTimestamp()
MsgBox % "Finished! It took " . (end - start) / 1000 .
" seconds to record pixel data from a " .
width . " x " . height . " area of the screen (" . resultCounter . " pixels)."
getTimestamp()
{
DllCall("QueryPerformanceCounter", "Int64*", timestamp)
DllCall("QueryPerformanceFrequency", "Int64*", frequency)
return Round(timestamp * 1000 / frequency)
}
If you'd like the version which includes debug logging and exporting of the data to an XML file for inspection, it's here.
Is there any faster way to get pixel data from a portion of the screen?
PixelSearch
searches very large areas of the screen very quickly, I'm not sure why PixelGetColor
would be so very slow in comparison. There must be some .dll
or some other function I can use to get pixel data from a small area of the screen much faster than this.