Wurschtbrot Posted November 22, 2009 Share Posted November 22, 2009 i need a function that "counts" or "calculates a uniq id" of all white(0xFFFFFF) if possible any hexcolor pixels from x,y to x,y WhiteCounter(100, 100, 200, 200) Func WhiteCounter($whiteX, $whiteY, $whiteXX, $whiteYY) $whitetemp = 0 For $whitetempX = $whiteX To $whiteXX step 1 For $whitetempY = $whiteY To $whiteYY step 1 if Dec("FFFFFF") = PixelGetColor($whitetempX, $whitetempY) Then $whitetemp += 1 Next Next Return $whitetemp EndFunc ;==>WhiteCounter this func is way to slow, in some cases i have to call Pixelgetcolor 100k times ... screen res is 1920x1080 and if i change Step it's not accurate anymore Link to comment Share on other sites More sharing options...
AndyG Posted November 23, 2009 Share Posted November 23, 2009 Hi, try this...expandcollapse popup#include <Array.au3> #include <GDIPlus.au3> #include <GDIPlusConstants.au3> #include <ScreenCapture.au3> #include <StructureConstants.au3> #include <WinAPI.au3> $t = TimerInit() $count = WhiteCounter(1300, 200, 1400, 300) $m = TimerDiff($t) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : time = ' & $m & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $count = ' & $count & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $t = TimerInit() $count = WhiteCounter2(1300, 200, 1400, 300) $m = TimerDiff($t) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : time = ' & $m & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $count = ' & $count & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Func WhiteCounter($whiteX, $whiteY, $whiteXX, $whiteYY) $whitetemp = 0 For $whitetempX = $whiteX To $whiteXX Step 1 For $whitetempY = $whiteY To $whiteYY Step 1 If Dec("FFFFFF") = PixelGetColor($whitetempX, $whitetempY) Then $whitetemp += 1 Next Next Return $whitetemp EndFunc ;==>WhiteCounter2 Func WhiteCounter2($whiteX, $whiteY, $whiteXX, $whiteYY) _GDIPlus_Startup() $hbScreen = _ScreenCapture_Capture("", $whiteX, $whiteY, $whiteXX, $whiteYY, False) If @error Then MsgBox(0, "", "Fehler Screencapturewnd") $pBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbScreen); returns memory bitmap If @error Then MsgBox(0, "", "Fehler BitmapCreateFromHBITMAP File") ;_GDIPlus_BitmapLockBits gibt $tagGDIPBITMAPDATA-Struktur zurück $BitmapData = _GDIPlus_BitmapLockBits($pBitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $GDIP_PXF24RGB) If @error Then MsgBox(0, "", "Error locking region " & @error) $Stride = DllStructGetData($BitmapData, "Stride");Stride - Offset, in bytes, between consecutive scan lines of the bitmap. If the stride is positive, the bitmap is top-down. If the stride is negative, the bitmap is bottom-up. $Width = DllStructGetData($BitmapData, "Width");Image width - Number of pixels in one scan line of the bitmap. $Height = DllStructGetData($BitmapData, "Height");Image height - Number of scan lines in the bitmap. ;$pixelFormat = DllStructGetData($BitmapData, "PixelFormat");Pixel format - Integer that specifies the pixel format of the bitmap $Scan0 = DllStructGetData($BitmapData, "Scan0");Scan0 - Pointer to the first (index 0) scan line of the bitmap. $pixeldata = DllStructCreate("byte[" & (Abs($Stride) * ($Height)) & "]", $Scan0) ;$BMPDataStart = DllStructGetData($pixeldata, 1) ;string im Struct-format, d.h. Byte+nulByte, in dem die pixeldaten im BGR-Format stehen $BMP = StringTrimLeft(DllStructGetData($pixeldata, 1), 2) $r = StringReplace($BMP, "FFFFFF", "BBBBBB") $w = @extended $BMP = "" $pixeldata = 0 _GDIPlus_BitmapUnlockBits($pBitmap, $BitmapData) _GDIPlus_ImageDispose($pBitmap) _WinAPI_DeleteObject($hbscreen) _GDIPlus_Shutdown() Return $w EndFunc ;==>WhiteCounterit´s 15 times faster, but there are 2 different sum of white pixel! My function returns on a white screen 10000 (100x100pixel) but your function returns 10102(101x101pixel).You should adapt this. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now