|
You last visited: Today at 03:31
Advertisement
PixelSearch Slow with Windows 10 and MEmu / BlueStacks
Discussion on PixelSearch Slow with Windows 10 and MEmu / BlueStacks within the AutoIt forum part of the Coders Den category.
01/22/2017, 21:41
|
#1
|
elite*gold: 0
Join Date: Jan 2017
Posts: 2
Received Thanks: 0
|
PixelSearch Slow with Windows 10 and MEmu / BlueStacks
I've got a pixelsearch script that worked well until I upgraded from Windows 7 to Windows 10. In Windows 7, I had disabled Aero. Windows 10, however does not allow disabling Desktop Composition which is slowing down PixelSearch.
I'm looking to learn how to speed up pixelsearch so that I can use ControlClick to click on an Android Emulator - currently using MEmu. Can anyone provide a short example of using GDIPlus if that is the faster route to go? With PixelSearch a small 100x100 search takes a few seconds which is too slow for me.
I would like to do the following:
- PixelSearch in a control a certain color and get the coords,
- ControlClick the found coordinate
- this search would need to happen several times in a second or 2
Any help would be appreciated. I've pulled various GDI examples, but I'm too noob to get an efficient way to do it.
Thanks.
|
|
|
01/23/2017, 22:26
|
#2
|
elite*gold: 138
Join Date: Apr 2012
Posts: 3,495
Received Thanks: 1,769
|
Quote:
Originally Posted by WnG88
With PixelSearch a small 100x100 search takes a few seconds which is too slow for me.
|
That's really, really slow. Do you have an average PC or a cheaper one? If you show us the PixelSearch part of your code, maybe we can find some efficiency optimization but if it takes that long, I'm afraid it must be down to your slow PC
|
|
|
01/23/2017, 23:18
|
#3
|
elite*gold: 0
Join Date: Jan 2013
Posts: 426
Received Thanks: 129
|
There you are. This should work faster in this case.
Code:
#include <GDIPlus.au3>
_GDIPlus_Startup()
$hGUI = GUICreate("Test", 100, 100)
GUISetState()
Global $ahGraphics[3] = [_GDIPlus_GraphicsCreateFromHWND($hGUI)]
$ahGraphics[1] = _GDIPlus_BitmapCreateFromGraphics(100, 100, $ahGraphics[0])
$ahGraphics[2] = _GDIPlus_ImageGetGraphicsContext($ahGraphics[1])
While GUIGetMsg() <> -3
_GDIPlus_GraphicsClear($ahGraphics[2], 0xFFFFFFFF)
$hBitmap = _ScreenCapture_Capture("", 0, 0, 100, 100, WinGetHandle("[active]"))
_GDIPlus_GraphicsDrawImage($ahGraphics[2], $hBitmap , 0, 0)
_GDIPlus_GraphicsDrawImage($ahGraphics[0], $ahGraphics[1], 0, 0)
WEnd
Func __Pixelsearchbitmap($hBitmap, $iW, $iH, $iColor, $iTolerance = 0)
Local $i, $j, $iColor2, $iRed, $iGreen, $iBlue, $aRGB[3] = [Dec(StringLeft(Hex($iColor, 6), 2)), Dec(StringLeft(Hex($iColor, 4), 2)), Dec(Hex($iColor, 2))], $aRet[2]
For $i = 0 To $iW - 1
For $j = 0 To $iH - 1
$iColor2 = _GDIPlus_BitmapGetPixel($hBitmap, $i, $j)
$iRed = Dec(StringLeft(Hex($iColor2, 6), 2))
$iGreen = Dec(StringLeft(Hex($iColor2, 4), 2))
$iBlue = Dec(Hex($iColor2, 2))
If Abs($aRGB[0] - $iRed) + Abs($aRGB[1] - $iGreen) + Abs($aRGB[2] - $iBlue) < $iTolerance Then
$aRet[0] = $i
$aRet[1] = $j
Return $aRet
EndIf
Next
Next
Return SetError(1, 1, False)
EndFunc
Func _ScreenCapture_Capture($sFileName = "", $iLeft = 0, $iTop = 0, $iRight = -1, $iBottom = -1, $hWindow = 0)
If $iRight = -1 Then $iRight = _WinAPI_GetSystemMetrics(0) - 1
If $iBottom = -1 Then $iBottom = _WinAPI_GetSystemMetrics(1) - 1
If $iRight < $iLeft Then Return SetError(-1, 0, 0)
If $iBottom < $iTop Then Return SetError(-2, 0, 0)
Local $iW = ($iRight - $iLeft) + 1
Local $iH = ($iBottom - $iTop) + 1
Local $hWnd = _WinAPI_GetDesktopWindow()
If $hWindow = 0 Then
Local $hDDC = _WinAPI_GetDC($hWnd)
Else
Local $hDDC = _WinAPI_GetDC($hWindow)
EndIf
Local $hCDC = _WinAPI_CreateCompatibleDC($hDDC)
Local $hBMP = _WinAPI_CreateCompatibleBitmap($hDDC, $iW, $iH)
_WinAPI_SelectObject($hCDC, $hBMP)
_WinAPI_BitBlt($hCDC, 0, 0, $iW, $iH, $hDDC, $iLeft, $iTop, 0x00CC0020)
_WinAPI_ReleaseDC($hWnd, $hDDC)
_WinAPI_DeleteDC($hCDC)
Return _GDIPlus_BitmapCreateFromHBITMAP($hBMP)
EndFunc ;==>_ScreenCapture_Capture
Is that understandable enough for you to use? I took the _screencapture_capture function and modified it to return a bitmap, and to be able to view a window you choose (in this example: WinGetHandle("[active]") (the window that is currently active (try switching windows and see how it changes too))). Just replace "[Active]" with the name of the Bluestacks window, and write your bot code into the while loop. Feel free to remove the GUI, and all lines that have $ahGraphics[0]/[1]/[2] in them.
|
|
|
02/04/2017, 01:57
|
#4
|
elite*gold: 0
Join Date: Jan 2017
Posts: 2
Received Thanks: 0
|
Thanks Guys!
Trying the code out. I have an i7 4700k - so cpu isn't the prob. Everything i researched says it is related to Windows 10 and Desktop Composition (AERO) which slows down PixelSearch. I'm trying out the GDI code now and will update.
|
|
|
Similar Threads
|
Windows 10 slow as fk
06/18/2016 - Technical Support - 3 Replies
Hi,
hab seit kurzem Windows 10 und ich habe ohne Witz 4+ Stunden gebraucht um eine 12gb Datei von meinem USB Stick aufm Rechner zu tun. Wieso dauert das so lang und wie kann ichs beheben?
Specs: 8gb ram, amd fx 6100, r9 280, 1.5tb speicher
|
[S] Windows Server wo Bluestacks läuft (!) [B] e*gold, PSC
06/10/2015 - elite*gold Trading - 5 Replies
titel ^^ dringend
|
All times are GMT +2. The time now is 03:31.
|
|