GDIPlus slow ScreenCapture

06/17/2020 21:59 Silbi#1
I need to check the color of exactly 1 pixel that always has the same coordinates.

On Windows 10 with Aero my pc takes around 17ms to check the color on the desktop and over 30ms with moving images.

The most time is spent on the _ScreenCapture_Capture function although it only captures 1 pixel.

Is there any faster implementation for this?



I'm using this to calculate the average computing time per pixel:
Code:
#include <GDIPlus.au3> ; for GDI+
#include <ScreenCapture.au3>

; GDI+ method
_GDIPlus_Startup() ;initialize GDI+
$n1 = 200 ; iterations
$start_time=TimerInit()
For $i = 1 To $n1
	Local $iColor = 0
	Local $hHBmp = _ScreenCapture_Capture("", 0, 0, 1, 1) ;create a GDI bitmap by capturing an area on desktop
	Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap
	_WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
	$iColor = _GDIPlus_BitmapGetPixel($hBitmap, 0, 0) ;get current pixel color
Next
$time=int(TimerDiff($start_time))/$n1
ConsoleWrite("GDIPlus average ms/pixel: "&$time&@crlf)

;cleanup GDI+ resources
_GDIPlus_Shutdown()

Exit
06/18/2020 18:24 elmarcia#2
Quote:
Originally Posted by Silbi View Post
I need to check the color of exactly 1 pixel that always has the same coordinates.

On Windows 10 with Aero my pc takes around 17ms to check the color on the desktop and over 30ms with moving images.

The most time is spent on the _ScreenCapture_Capture function although it only captures 1 pixel.

Is there any faster implementation for this?



I'm using this to calculate the average computing time per pixel:
Code:
#include <GDIPlus.au3> ; for GDI+
#include <ScreenCapture.au3>

; GDI+ method
_GDIPlus_Startup() ;initialize GDI+
$n1 = 200 ; iterations
$start_time=TimerInit()
For $i = 1 To $n1
	Local $iColor = 0
	Local $hHBmp = _ScreenCapture_Capture("", 0, 0, 1, 1) ;create a GDI bitmap by capturing an area on desktop
	Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI to GDI+ bitmap
	_WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore
	$iColor = _GDIPlus_BitmapGetPixel($hBitmap, 0, 0) ;get current pixel color
Next
$time=int(TimerDiff($start_time))/$n1
ConsoleWrite("GDIPlus average ms/pixel: "&$time&@crlf)

;cleanup GDI+ resources
_GDIPlus_Shutdown()

Exit
Your code is similar to this one, unfortunately since autoit is an interpreted language performance time won't improve
Code:
#include <WinAPI.au3>
$desktopHWND = 0
$desktop_dc = _WinAPI_GetDC($desktopHWND)
$hDll = DllOpen("gdi32.dll")

$n1 = 200 ; iterations
$x = 15
$y = 15
$start_time=TimerInit()

For $i = 1 To $n1
	$res = DllCall($hDll,"dword","GetPixel","HANDLE",$desktop_dc,"int",$x,"int",$y); returns dword of pixel color
 Next


$time=int(TimerDiff($start_time))/$n1
MsgBox(0,"","GDIPlus average ms/pixel: "&$time&@crlf)

 DllClose($hDll)
As you can see you can use c++ for this task since it uses windows apis

Edit 2:
C++ time still 16ms which it isn't that bad