speed and effeciency is of utmost importance to me so i ran some tests using GDIP library. previously ive just been using GDI GetPixel
according to my tests, both GDIP methods are slower than normal GetPixel. maybe i'm doing things wrong?
heres my code, mouseover a window and press f3
OnExit, ExitSub #include gdip.ahk If !pToken := Gdip_Startup() { MsgBox, 48, gdiplus error!, Gdiplus failed to start. Please ensure you have gdiplus on your system ExitApp } return ;// end of autoexec f3:: tooltip, scanning pixels - please wait MouseGetPos,,, win loops := 10 xx := 40 yy := 50 ;// AHK PixelGetColor PGCstartTime := A_TickCount Loop, %loops% { WinActivate, ahk_id %win% PixelGetColor, PGCcolor, xx, yy } PGCtime := A_TickCount-PGCstartTime ;// GDI GetPixel PCAStartTime := A_TickCount Loop, %loops% { PCAcolor := GetPixel(xx, yy, win) } PCAtime := A_TickCount-PCAStartTime ;// Gdip_GetPixel GDIPGPstartTime := A_TickCount Loop, %loops% { GDIPGPcolor := GdipGetPixel(xx, yy, win) } GDIPGPtime := A_TickCount - GDIPGPstartTime ;// Gdip_LockBits GDIPLstartTime := A_TickCount Loop, %loops% { GDIPLcolor := GetLockBitPixel(xx, yy, win) } GDIPLtime := A_TickCount - GDIPLstartTime tooltip, msgboxstr := "AHK PixelGetColor`n" . PGCcolor . "`nfound " . loops . " times in " . PGCtime . "ms`n`n" msgboxstr .= "GDI GetPixel`n" . PCAcolor . "`nfound " . loops . " times in " . PCAtime . "ms`n`n" msgboxstr .= "Gdip GetPixel`n" . GDIPGPcolor . "`nfound " . loops . " times in " . GDIPGPtime . "ms`n`n" msgboxstr .= "Gdip GetLockBitPixel`n" . GDIPLcolor . "`nfound " . loops . " times in " . GDIPLtime . "ms" msgbox, %msgboxstr% return ExitSub: Gdip_Shutdown(pToken) ExitApp return GetPixel(col_x,col_y,id) { pix := "" WinGetPos, , , w, h, ahk_id %id% hDC := DllCall("GetDC", "UInt", id) hCDC := DllCall("gdi32.dll\CreateCompatibleDC", "UInt", hDC) hBMP := DllCall("gdi32.dll\CreateCompatibleBitmap", "UInt", hDC, "Int", w, "Int", h) hOldObj := DllCall("gdi32.dll\SelectObject", "UInt", hCDC, "UInt", hBMP) DllCall("PrintWindow", "UInt", id, "UInt", hCDC, "UInt", 0) DllCall("RedrawWindow", "UInt", id, "UInt", 0, "UInt", 0, "UInt", 1|16|32|64|1024) pix := DllCall("GetPixel", "UInt", hCDC, "Int", col_x, "Int", col_y) oldfrmt := A_FormatInteger SetFormat, IntegerFast, hex pix += 0 pix .= "" SetFormat, IntegerFast, %oldfrmt% DllCall("gdi32.dll\SelectObject", "UInt", hCDC, "UInt", hOldObj) DllCall("gdi32.dll\ReleaseDC", "UInt", id, "UInt", hDC) DllCall("gdi32.dll\DeleteObject", "UInt", hBMP) DllCall("gdi32.dll\DeleteDC", "UInt", hCDC) DllCall("gdi32.dll\DeleteDC", "UInt", hDC) return pix } GetLockBitPixel(x,y,id) { if (!pBitmap := Gdip_BitmapFromHWND(id)) { MsgBox, 48, error getting bitmap ExitApp } Width1 := Gdip_GetImageWidth(pBitmap) Height1 := Gdip_GetImageHeight(pBitmap) Gdip_LockBits(pBitmap, 0, 0, Width1, Height1, Stride1, Scan1, BitmapData1) GDIPcolor := Gdip_GetLockBitPixel(Scan1, x, y, Stride1) ;Gdip_FromARGB(Gdip_GetLockBitPixel(Scan1, x, y, Stride1), a, r, g, b) ;GDIPcolor := r . g . b oldfrmt := A_FormatInteger SetFormat, IntegerFast, hex GDIPcolor += 0 GDIPcolor .= "" SetFormat, IntegerFast, %oldfrmt% Gdip_UnlockBits(pBitmap, BitmapData1) Gdip_DisposeImage(pBitmap) return GDIPcolor } GdipGetPixel(x, y, id) { if (!pBitmap := Gdip_BitmapFromHWND(id)) { MsgBox, 48, error getting bitmap ExitApp } GDIPcolor := Gdip_GetPixel(pBitmap, x, y) ;Gdip_FromARGB(Gdip_GetPixel(pBitmap, x, y), a, r, g, b) ;GDIPcolor := r . g . b oldfrmt := A_FormatInteger SetFormat, IntegerFast, hex GDIPcolor += 0 GDIPcolor .= "" SetFormat, IntegerFast, %oldfrmt% Gdip_DisposeImage(pBitmap) return GDIPcolor }