How can I get the pixel data from an area of the screen (much) faster in AHK?

后端 未结 2 563
长发绾君心
长发绾君心 2021-01-15 03:23

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

2条回答
  •  春和景丽
    2021-01-15 04:05

    To reduce delays between commands to a minimum you should also use SetBatchLines, -1. This alone can give you a significant performance boost.
    I think you have already figured out the rest.
    But in case anyone else stumbles across this question. Here is how you can do it with GDI+:

    SetBatchLines, -1
    
    #Include Gdip.ahk
    
    pToken := Gdip_Startup()
    
    ; Screen area ("X|Y|Width|Height")
    pBitmap := Gdip_BitmapFromScreen("500|600|300|100")
    
    ; Read RGB color from pixel x290 y65
    ARGB := Gdip_GetPixel( pBitmap, 290, 65 )
    pixelColor := ARGBtoRGB( ARGB )
    MsgBox, % pixelColor
    
    ; Read RGB color from pixel x167 y90
    ARGB := Gdip_GetPixel( pBitmap, 167, 90 )
    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
    }
    

    The code is mostly what I already posted in another answer right here.

提交回复
热议问题