#include <Array.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
$timer = TimerInit()
$Color = '860CFF' ; цвет без '0x'
$aMatrix = _DesktopMatrix($Color)
ConsoleWrite(TimerDiff($timer) & @CR)
_ArrayDisplay($aMatrix, $Color)
Func _DesktopMatrix($sColor)
Local $hBmp, $hBitmap2, $tMap, $bData2, $Width, $Height, $n = 0
_GDIPlus_Startup()
$hBmp = _ScreenCapture_Capture('', 0, 0, 500, 500) ; координаты прямоугольника скриншота
$hBitmap2 = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
$Width = _GDIPlus_ImageGetWidth($hBitmap2) - 1
$Height = _GDIPlus_ImageGetHeight($hBitmap2) - 1
$tMap = _GDIPlus_BitmapLockBits($hBitmap2, 0, 0, $Width, $Height, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
$bData2 = DllStructGetData(DllStructCreate('byte[' & ($Width * $Height * 4) & ']', DllStructGetData($tMap, 'Scan0')), 1)
_GDIPlus_BitmapUnlockBits($hBitmap2, $tMap)
_GDIPlus_BitmapDispose($hBitmap2)
_GDIPlus_Shutdown()
$bData2 = '######FF' & StringTrimLeft($bData2, 2)
$sColor = StringRegExpReplace($sColor, '(.{2})(.{2})(.{2})', '\3\2\1')
$ext = StringRegExp($bData2, $sColor, 3)
If Ubound($ext) - 1 > 0 Then
$aTemp = StringRegExp($bData2, '(\S{6})FF', 3)
Dim $uArray[Ubound($ext)][2] = [[0]]
For $i = 0 To UBound($aTemp) - 1
If $aTemp[$i] = $sColor Then
$y = Floor($i / ($Width))
$x = ($i - $y * $Width)
$uArray[$n][0] = $x
$uArray[$n][1] = $y
$n += 1
EndIf
Next
Else
Return SetError(1, 0, 0)
EndIf
Return $uArray
EndFunc ;==>_DesktopMatrix1
$ext = StringRegExp($bData2, $sColor, 3)
_ArrayFindAll
#include <Array.au3>
#include <GDIP.au3>
#include <ScreenCapture.au3>
$timer = TimerInit()
$Color = 'FFFFFF' ; цвет без '0x'
$aMatrix = _DesktopMatrix1($Color)
ConsoleWrite(TimerDiff($timer) & @CR)
_ArrayDisplay($aMatrix, $Color)
Func _DesktopMatrix1($sColor)
Local $hBmp, $hBitmap2, $tMap, $bData2, $Width, $Height
_GDIPlus_Startup()
$hBmp = _ScreenCapture_Capture('', 0, 0, 500, 500) ; координаты прямоугольника скриншота
$hBitmap2 = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
$Width = _GDIPlus_ImageGetWidth($hBitmap2) - 1
$Height = _GDIPlus_ImageGetHeight($hBitmap2) - 1
$tMap = _GDIPlus_BitmapLockBits($hBitmap2, 0, 0, $Width, $Height, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
$bData2 = DllStructGetData(DllStructCreate('byte[' & ($Width * $Height * 4) & ']', DllStructGetData($tMap, 'Scan0')), 1)
_GDIPlus_BitmapUnlockBits($hBitmap2, $tMap)
_GDIPlus_BitmapDispose($hBitmap2)
_GDIPlus_Shutdown()
$bData2 = '######FF' & StringTrimLeft($bData2, 2)
$sColor = StringRegExpReplace($sColor, '(.{2})(.{2})(.{2})', '\3\2\1')
If StringInStr($bData2, $sColor) Then
$aTemp = StringRegExp($bData2, '(\S{6})FF', 3)
$aiResult = _ArrayFindAll($aTemp, $sColor)
If $aiResult <> -1 Then
Dim $uArray[UBound($aiResult)][2] = [[0]]
For $i = 0 To UBound($aiResult) - 1
$y = Floor($aiResult[$i] / ($Width))
$x = ($aiResult[$i] - $y * $Width)
$uArray[$i][0] = $x
$uArray[$i][1] = $y
Next
Else
Return SetError(1, 0, 0)
EndIf
Return $uArray
Else
Return SetError(1, 0, 0)
EndIf
EndFunc ;==>_DesktopMatrix
Попробуйте поменять наКак раз с FFFFFF могут быть ошибки
;...
$sColor = StringRegExpReplace($sColor, '(.{2})(.{2})(.{2})', '\3\2\1FF')
$aTemp = StringRegExp($bData2, '.{8}', 3)
;...
#include <Array.au3>
#include <GDIP.au3>
#include <ScreenCapture.au3>
$timer = TimerInit()
$Color = 'FFFFFF' ; цвет без '0x'
$aMatrix = _DesktopMatrix1($Color)
ConsoleWrite(TimerDiff($timer) & @CR)
_ArrayDisplay($aMatrix, $Color)
Func _DesktopMatrix1($sColor)
Local $hBmp, $hBitmap2, $tMap, $bData2, $Width, $Height
_GDIPlus_Startup()
$hBmp = _ScreenCapture_Capture('', 0, 0, 10, 10) ; координаты прямоугольника скриншота
$hBitmap2 = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
$Width = _GDIPlus_ImageGetWidth($hBitmap2) - 1
$Height = _GDIPlus_ImageGetHeight($hBitmap2) - 1
$tMap = _GDIPlus_BitmapLockBits($hBitmap2, 0, 0, $Width, $Height, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
$bData2 = DllStructGetData(DllStructCreate('byte[' & ($Width * $Height * 4) & ']', DllStructGetData($tMap, 'Scan0')), 1)
_GDIPlus_BitmapUnlockBits($hBitmap2, $tMap)
_GDIPlus_BitmapDispose($hBitmap2)
_GDIPlus_Shutdown()
$bData2 = '######FF' & StringTrimLeft($bData2, 2)
$sColor = StringRegExpReplace($sColor, '(.{2})(.{2})(.{2})', '\3\2\1')
If StringInStr($bData2, $sColor) Then
$aTemp = StringRegExp($bData2, '(\S{6})FF', 3)
$aiResult = _ArrayFindAll($aTemp, $sColor)
If $aiResult <> -1 Then
Dim $uArray[UBound($aiResult)][3] = [[0]]
For $i = 0 To UBound($aiResult) - 1
$y = Floor($aiResult[$i] / ($Width))
$x = ($aiResult[$i] - $y * $Width)
$uArray[$i][0] = $x
$uArray[$i][1] = $y
$uArray[$i][2] = Hex(PixelGetColor($x, $y), 6)
Next
Else
Return SetError(1, 0, 0)
EndIf
Return $uArray
Else
Return SetError(1, 0, 0)
EndIf
EndFunc ;==>_DesktopMatrix
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <Array.au3>
Local $sColor = 'FFFFFF', $aRet[1]
_GDIPlus_Startup()
$hBmp = _ScreenCapture_Capture('', 0, 0, 10, 10)
$hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBmp)
$iWidth = _GDIPlus_ImageGetWidth($hBitmap) - 1
$iHeight = _GDIPlus_ImageGetHeight($hBitmap) - 1
$tMap = _GDIPlus_BitmapLockBits($hBitmap, 0, 0, $iWidth, $iHeight, $GDIP_ILMREAD, $GDIP_PXF32ARGB)
$sData = Hex(DllStructGetData(DllStructCreate('byte[' & ($iWidth * $iHeight * 4) & ']', DllStructGetData($tMap, 'Scan0')), 1))
_GDIPlus_BitmapUnlockBits($hBitmap, $tMap)
_GDIPlus_BitmapDispose($hBitmap)
_GDIPlus_Shutdown()
$sTmpColor = StringRegExpReplace($sColor, '(.{2})(.{2})(.{2})', '\3\2\1FF')
$aTemp = StringRegExp($sData, '.{8}', 3)
ReDim $aRet[UBound($aTemp) + 1][3]
For $i = 0 To UBound($aTemp) - 1
If $aTemp[$i] = $sTmpColor Then
$aRet[0][0] += 1
$aRet[$aRet[0][0]][1] = Floor($i / ($iWidth))
$aRet[$aRet[0][0]][0] = ($i - $aRet[$aRet[0][0]][1] * $iWidth)
$aRet[$aRet[0][0]][2] = Hex(PixelGetColor($aRet[$aRet[0][0]][0], $aRet[$aRet[0][0]][1]), 6)
EndIf
Next
ReDim $aRet[$aRet[0][0] + 1][3]
_ArrayDisplay($aRet, $sColor)
;...
$iWidth = _GDIPlus_ImageGetWidth($hBitmap) - 1
$iHeight = _GDIPlus_ImageGetHeight($hBitmap) - 1
;...
;...
$aTemp = DllCall($ghGDIPDll, 'uint', 'GdipGetImageDimension', 'ptr', $hBitmap, 'float*', 0, 'float*', 0)
;If @error Or $aTemp[0] Then Exit _GDIPlus_Shutdown()
$iWidth = $aTemp[2] - 1
$iHeight = $aTemp[3] - 1
;...
#include <Array.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
$Timer = TimerInit()
$Arr = MultiPixel(0, 0, 50, 50)
ConsoleWrite(TimerDiff($Timer)/1000)
_ArrayDisplay($Arr)
Func MultiPixel($l, $t, $r, $b, $c="FFFFFF")
Local $x=0, $y=0, $i=0, $j=0
Local $Width = $r-$l, $Height = $b-$t
Dim $Res[$Width*$Height][2]
;Dim $Res[1]
_GDIPlus_Startup()
$Data = Hex(DllStructGetData(DllStructCreate('byte[' & ($Width * $Height * 4) & ']', DllStructGetData(_GDIPlus_BitmapLockBits(_GDIPlus_BitmapCreateFromHBITMAP(_ScreenCapture_Capture('', $l, $t, $r, $b)), 0, 0, $Width, $Height, $GDIP_ILMREAD, $GDIP_PXF32ARGB), 'Scan0')), 1), 6)
_GDIPlus_Shutdown()
$Width -= 1
For $j=0 To StringLen($Data) Step 8
If $x >= $Width Then
$x = 0
$y += 1
ContinueLoop
EndIf
If StringMid($Data, $j, 6)==$c Then
$Res[$i][0] = $x
$Res[$i][1] = $y
;$Res[$i][2] = Hex(PixelGetColor($x, $y), 6)
$i += 1
EndIf
$x += 1
Next
If $i < 1 Then
SetError(1)
Return False
EndIf
ReDim $Res[$i][2]
Return $Res
EndFunc
$Data = Hex(
DllStructGetData(
DllStructCreate('byte[' & ($Width * $Height * 4) & ']',
DllStructGetData(
_GDIPlus_BitmapLockBits(
_GDIPlus_BitmapCreateFromHBITMAP(
_ScreenCapture_Capture('', $l, $t, $r, $b)
), 0, 0, $Width, $Height, $GDIP_ILMREAD, $GDIP_PXF32ARGB
), 'Scan0'
)
), 1
), 6
)
Func toPoint(ByRef $Arr, $e=1)
$i=1
While $i < UBound($Arr)
For $j=0 To $i-1
If (Abs($Arr[$i][0]-$Arr[$j][0]) <= $e And Abs($Arr[$i][1]-$Arr[$j][1]) <= $e) Then
_ArrayDelete($Arr, $j)
$i -= 2
ExitLoop
EndIf
Next
$i += 1
WEnd
EndFunc
toPoint($Arr)
#include <WinAPI.au3>
$c = ClientArea()
MouseMove($c[0], $c[1])
Func ClientArea($Class = "[ACTIVE]")
$Wnd = WinGetHandle($Class)
Local $Point = DllStructCreate("int X;int Y")
DllStructSetData($Point, "X", 00)
DllStructSetData($Point, "Y", 0)
_WinAPI_ClientToScreen($Wnd, $Point)
Dim $Arr[2] = [DllStructGetData($Point, "X"), DllStructGetData($Point, "Y")]
Return $Arr
EndFunc
#include <GDIPlus.au3>
#include <ScreenCapture.au3>
Opt("PixelCoordMode", 2)
Opt("MouseCoordMode", 2)
Opt("CaretCoordMode", 2)
Sleep(3000)
$Timer = TimerInit()
Dim $Point[2] = [25, 25]
$A = PointSearch("FFFFFF", $Point, 0, 0, 100, 100)
If Not IsArray($A) Then
l("Color", "not found!")
Exit 0
EndIf
l("Timer", TimerDiff($Timer)/1000)
l("Lenght", Int($A[2]))
l("Coords", "x"&$A[0]&", y"&$A[1])
l("Color", "#"&Hex(PixelGetColor($A[0], $A[1]), 6))
MouseMove($A[0], $A[1])
Func l($k, $v)
ConsoleWrite($k&": "&$v&@CRLF)
EndFunc
Func PointSearch($c, $p, $l, $t=0, $r=0, $b=0, $e=1)
$Arr = MultiPixel($l, $t, $r, $b, $c)
If $Arr == False Then Return False
$Arr = toPoint($Arr, $e)
If Not IsArray($Arr) Then Return False
Dim $Coords[3] = [0, 0, 0]
For $i=0 To UBound($Arr)-1
$Len = Sqrt(($Arr[$i][0]-$p[0])^2+($Arr[$i][1]-$p[1])^2)
If $Len < $Coords[2] Or $Coords[2] == 0 Then
$Coords[0] = $Arr[$i][0]
$Coords[1] = $Arr[$i][1]
$Coords[2] = $Len
EndIf
Next
Return $Coords
EndFunc
Func MultiPixel($l, $t, $r, $b, $c="FFFFFF")
Local $x=0, $y=0, $i=0, $j=0
If Opt("PixelCoordMode")<>1 Then
$ca = ClientArea()
$l += $ca[0]
$t += $ca[1]
$r += $ca[0]
$b += $ca[1]
EndIf
Local $Width = $r-$l, $Height = $b-$t
Dim $Res[$Width*$Height][2]
_GDIPlus_Startup()
$Data = Hex(DllStructGetData(DllStructCreate('byte[' & ($Width * $Height * 4) & ']', DllStructGetData(_GDIPlus_BitmapLockBits(_GDIPlus_BitmapCreateFromHBITMAP(_ScreenCapture_Capture('', $l, $t, $r, $b)), 0, 0, $Width, $Height, $GDIP_ILMREAD, $GDIP_PXF32ARGB), 'Scan0')), 1), 6)
_GDIPlus_Shutdown()
$Width -= 1
For $j=1 To StringLen($Data) Step 8
If $x >= $Width Then
$x = 0
$y += 1
ContinueLoop
EndIf
$s = StringMid($Data, $j, 6)
$s = StringMid($s, 5, 2)&StringMid($s, 3, 2)&StringMid($s, 1, 2)
If $s==$c Then
$Res[$i][0] = $x
$Res[$i][1] = $y
$i += 1
EndIf
$x += 1
Next
If $i < 1 Then
SetError(1)
Return False
EndIf
ReDim $Res[$i][2]
Return $Res
EndFunc
Func toPoint(ByRef $Arr, $e=1)
Local $k=0
Dim $Res[UBound($Arr)][2]
For $i=0 To UBound($Arr)-1
$n=$i
For $j=$i+1 To UBound($Arr)-1
If Not((Abs($Arr[$j][0]-$Arr[$n][0]) > $e Or Abs($Arr[$j][1]-$Arr[$n][1]) > $e)) Then $n = $j
Next
If $n == $i Then
$Res[$k][0] = $Arr[$n][0]
$Res[$k][1] = $Arr[$n][1]
$k += 1
EndIf
Next
ReDim $Res[$k][2]
Return $Res
EndFunc
Func ClientArea($Class = "[ACTIVE]")
$Wnd = WinGetHandle($Class)
Local $Point = DllStructCreate("int X;int Y")
DllStructSetData($Point, "X", 00)
DllStructSetData($Point, "Y", 0)
_WinAPI_ClientToScreen($Wnd, $Point)
Dim $Arr[2] = [DllStructGetData($Point, "X"), DllStructGetData($Point, "Y")]
Return $Arr
EndFunc
Тоже столкнулся с проблемой быстрого поиска всех пикселей одного цвета. Ваша функция, действительно, самая быстрая из найденных мною на этом форуме. Но и самая неточная: в белом квадрате 10х10 находит 89 белых пикселей :(Я написал функцию, для мультипоиска цвета. Пожалуйста проверьте
#include <Array.au3>
#include <WinAPIEx.au3>
#include <WindowsConstants.au3>
$t = TimerInit()
$test = _PixelGetArray(200, 200, 100, 100, 0xFFFFFF)
ConsoleWrite(TimerDiff($t) & @LF)
_ArrayDisplay($test)
Func _PixelGetArray($iX, $iY, $iWidth, $iHeight, $iColor, $hWnd = 0)
Local $aPixels[$iWidth * $iHeight + 1][2]
Local $hDC = _WinAPI_GetDC($hWnd)
Local $hMemDC = _WinAPI_CreateCompatibleDC($hDC)
Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $iWidth, $iHeight)
_WinAPI_SelectObject($hMemDC, $hBitmap)
_WinAPI_BitBlt($hMemDC, 0, 0, $iWidth, $iHeight, $hDC, $iX, $iY, $SRCCOPY)
_WinAPI_DeleteDC($hMemDC)
_WinAPI_ReleaseDC($hWnd, $hDC)
Local $iSize = $iWidth * $iHeight
Local $tBits = DllStructCreate("dword[" & $iSize & "]")
_WinAPI_GetBitmapBits($hBitmap, 4 * $iSize, DllStructGetPtr($tBits))
Local $iCount = 0
For $i = 1 To $iSize
If BitAND(DllStructGetData($tBits, 1, $i), 0x00FFFFFF) = $iColor Then
$iCount += 1
$aPixels[$iCount][0] = Mod($i, $iWidth) - 1
If $aPixels[$iCount][0] = -1 Then $aPixels[$iCount][0] = $iWidth - 1
$aPixels[$iCount][1] = Ceiling($i / $iWidth) - 1
EndIf
Next
ReDim $aPixels[$iCount + 1][2]
$aPixels[0][0] = $iCount
Return $aPixels
EndFunc ;==>_PixelGetArray