如何从AHK的gdip库以网格格式获取位图数据? [英] How can I get bitmap data from gdip libraries in AHK in a grid format?

查看:232
本文介绍了如何从AHK的gdip库以网格格式获取位图数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做某种图像识别/运动检测,需要能够以某种坐标方式从屏幕访问像素数据,以便可以看到[350,425]处的像素是什么颜色,依此类推.

I'm doing some kind of image recognition / motion detection and need to be able to access the pixel data from the screen with some manner of coordinates so I can see what color the pixel at [350,425] is and so on.

我最近问了

I recently asked a question about getting pixel data from an area of the screen. The default method of viewing pixels in AHK is extremely slow (would take half a day to record the data from a 1080p screen). The answer seems to be using gdip libraries in AHK such as this one:

https://github.com/cswoyer/AutoHotkey/blob/master/ScreenCapture.ahk

但是我不知道如何在处理过程中以我可以使用的格式获取像素数据.我需要通过x,y坐标或遵循某种基本模式的格式来访问某种结构的数据,以便可以将其重新格式化为网格数据结构并使用它.

However I have no idea how to get the pixel data during the process in a format that I can work with. I need to access the data in some sort of structure is accessible via x,y coordinates, or a format that follows some basic pattern so I can reformat it into a grid data structure and work with it.

我一直在尝试检查各种变量以查找可以使用的任何类型的文本数据,但是我尝试过的所有变量似乎都不包含文本或对象数据.

I keep trying to check the various variables for any kind of text data that I can try to work with but none of them that I've tried seem to contain text or object data.

推荐答案

我不确定您要完成什么,但是将屏幕快照保存在变量中并从那里获取像素确实应该更快.但是显然,截取该屏幕截图将花费几毫秒,因此我不确定这对于运动检测"将有多大用处.

I'm not sure what you are trying to accomplish, but saving a screenshot in a variable and getting the pixels from there should be faster indeed. But obviously taking that screenshot will take a few milliseconds, so I'm not sure how useful this is gonna be in terms of "motion detection".

#SingleInstance, Force
SetBatchLines, -1
SetWorkingDir %A_ScriptDir%

#Include Gdip.ahk

pToken := Gdip_Startup()
pBitmap := Gdip_BitmapFromScreen() ; Make a screenshot

; Read RGB color from pixel x350 y425
ARGB := Gdip_GetPixel( pBitmap, 350, 425 )
pixelColor := ARGBtoRGB( ARGB )
MsgBox, % pixelColor

; Read RGB color from pixel x345 y567
ARGB := Gdip_GetPixel( pBitmap, 345, 567 )
pixelColor := ARGBtoRGB( ARGB )
MsgBox, % pixelColor


Gdip_DisposeImage(pBitmap)
Gdip_Shutdown(pToken)

ARGBtoRGB( ARGB ) {
 VarSetCapacity( RGB,6,0 )
 DllCall( "msvcrt.dll\sprintf", Str,RGB, Str,"%06X", UInt,ARGB<<8 )
 Return "0x" RGB
}

这两个职位的积分:
https://autohotkey.com/board/topic/47007-get-pixel-color-from-a-bmp/?p = 293766
https://autohotkey.com/board/topic/91427-gdi-how-to-get-bitmap-from-certain-area-of-screen/?p=576860

Credits to these two posts:
https://autohotkey.com/board/topic/47007-get-pixel-color-from-a-bmp/?p=293766
https://autohotkey.com/board/topic/91427-gdi-how-to-get-bitmap-from-certain-area-of-screen/?p=576860

Gdip.ahk可以在这里找到: https://github.com/tariqporter/Gdip/blob/master/Gdip.ahk

Gdip.ahk can be found here: https://github.com/tariqporter/Gdip/blob/master/Gdip.ahk

这篇关于如何从AHK的gdip库以网格格式获取位图数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆