【发布时间】:2017-11-21 03:39:27
【问题描述】:
我知道对于某些事情,用 C++ 编写某些事情会更好,但我真的希望能够在 AHK 中做到这一点:
我希望能够从屏幕的 100x300 区域检索像素数据,但是 PixelGetColor 太慢了。这是一个测试,证明每个像素大约需要 0.02 秒,大约需要 11.5 小时才能从整个 1920 x 1080 屏幕获取像素数据。
在测试中,从屏幕的 15 x 15 区域获取像素数据大约需要 4-5 秒。
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)
}
如果您想要包含调试日志记录和将数据导出到 XML 文件以供检查的版本,则为 here。
有没有更快的方法从屏幕的一部分获取像素数据?
PixelSearch 搜索屏幕的很大区域非常快,我不知道为什么 PixelGetColor 相比之下会非常慢。必须有一些.dll 或其他一些函数,我可以使用它来比这更快地从屏幕的一小块区域获取像素数据。
【问题讨论】:
-
也许拍摄一个屏幕截图,然后遍历图像以构建 2x2 像素颜色数组。不确定 AHK 是否能够实现这样的目标。我只是一直使用 PixelGetColor。
-
任何人都可以验证if this code example works for them? 我打算尝试使用它作为解决方案,但示例代码没有保存屏幕截图。
-
了解到我需要使用 ansi 32 位版本的 ahk 才能工作。仍在为此制定整体解决方案..
-
@ChickenFeet 如果您使用正确的 DLL,它可以:)
标签: autohotkey