goldenix Posted January 4, 2009 Share Posted January 4, 2009 I want to get pixel color from the screen & if its White replace it with gray & show the result. This is the part I dont understand: what do the numbers represent hire? I want to scan whole screen. but it wont work if I change it to this: Another problem, is that it wont work sometimes, it sorda blinks & he whole GUI turns white if i try to change $x & $y. any ideas? Example: notice $_width & $_height, what im doing wrong hire? expandcollapse popup;Using GDI+ BitmapSetPixel For $x = 0 To $_width For $y = 0 To $_height $iArgb = GDIPlus_BitmapGetPixel($hBitmap, $x, $y) If $iArgb = '0xFFFFFFFF' Then GDIPlus_BitmapSetPixel($hBitmap, $x, $y, 0xF2F2F2) Next NextoÝ÷ Ùj+)àr^jëh×6#include <GuiConstantsEx.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> Opt('MustDeclareVars', 1) _Main() Func _Main() Local $hGUI, $hBMP, $hBitmap, $hGraphic, $hDC, $aRet, $iArgb Local $_width = @DesktopWidth - 200 Local $_height = @DesktopHeight - 200 ; Capture upper left corner of screen $hBMP = _ScreenCapture_Capture("", 0, 0, $_width, $_height) ; Create GUI $hGUI = GUICreate("GDI+", $_width, $_height) GUISetState() ; Initialize GDI+ library _GDIPlus_Startup() $hDC = _WinAPI_GetDC($hGUI) ; Draw bitmap to GUI $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;~ ============================================================================================= ;Using GDI+ BitmapSetPixel For $x = 135 To 155 For $y = 115 To 165 ;Using GDI+ BitmapGetPixel $iArgb = GDIPlus_BitmapGetPixel($hBitmap, $x, $y) If $iArgb = '0xFFFFFFFF' Then GDIPlus_BitmapSetPixel($hBitmap, $x, $y, 0xF2F2F2) Next Next ;~ ============================================================================================= _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0) ; Using gdi32.dll GetPixel ;Used in forums search GetPixel $aRet = DllCall("gdi32.dll", "int", "GetPixel", "hwnd", $hDC, "int", 100, "int", 100) ConsoleWrite("GetPixel = 0x" & Hex($aRet[0], 6) & @LF) ;Using GDI+ BitmapGetPixel $iArgb = GDIPlus_BitmapGetPixel($hBitmap, 100, 100) ConsoleWrite("$iArgb = " & $iArgb & @LF) ; Using gdi32.dll SetPixel ;~ For $x = 5 To 15 ;~ For $y = 5 To 35 ;~ SetPixel($hGUI, $x, $y, "0x0000FF") ;~ Next ;~ Next ;~ ; Clean up resources _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hBitmap) _WinAPI_DeleteObject($hBMP) _WinAPI_ReleaseDC($hGUI, $hDC) ; Shut down GDI+ library _GDIPlus_Shutdown() ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>_Main ;The GetPixel method gets the color of a specified pixel in this bitmap. ;GdipBitmapGetPixel(GpBitmap* bitmap, INT x, INT y, ARGB *color) ; Func GDIPlus_BitmapGetPixel($hBitmap, $iX, $iY) Local $tArgb, $pArgb, $aRet $tArgb = DllStructCreate("dword Argb") $pArgb = DllStructGetPtr($tArgb) $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapGetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "ptr", $pArgb) Return "0x" & Hex(DllStructGetData($tArgb, "Argb")) EndFunc ;==>GDIPlus_BitmapGetPixel ; Write pixel to screen ; Used in forums search SetPixel ; Func SetPixel($handle, $x, $y, $color) Local $dc $dc = DllCall("user32.dll", "int", "GetDC", "hwnd", $handle) DllCall("gdi32.dll", "long", "SetPixel", "long", $dc[0], "long", $x, "long", $y, "long", $color) DllCall("user32.dll", "int", "ReleaseDC", "hwnd", 0, "int", $dc[0]) Return 1 EndFunc ;==>SetPixel ;The SetPixel method sets the color of a specified pixel in this bitmap. ;GdipBitmapSetPixel(GpBitmap* bitmap, INT x, INT y, ARGB color) ; Func GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, $iArgb) Local $aRet $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapSetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "dword", $iArgb) Return EndFunc ;==>GDIPlus_BitmapSetPixel My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] Link to comment Share on other sites More sharing options...
PsaltyDS Posted January 4, 2009 Share Posted January 4, 2009 I want to get pixel color from the screen & if its White replace it with gray & show the result. This is the part I dont understand: what do the numbers represent hire? I want to scan whole screen. but it wont work if I change it to this: Another problem, is that it wont work sometimes, it sorda blinks & he whole GUI turns white if i try to change $x & $y. any ideas? Example: notice $_width & $_height, what im doing wrong hire? ;Using GDI+ BitmapSetPixel For $x = 0 To $_width For $y = 0 To $_height $iArgb = GDIPlus_BitmapGetPixel($hBitmap, $x, $y) If $iArgb = '0xFFFFFFFF' Then GDIPlus_BitmapSetPixel($hBitmap, $x, $y, 0xF2F2F2) Next Next You detect white on a 32-bit all ones pattern ('0xFFFFFFFF'), but set the gray with a 24-bit RGB pattern ('0xF2F2F2'). Is there a format mismatch there? Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
goldenix Posted January 4, 2009 Author Share Posted January 4, 2009 (edited) You detect white on a 32-bit all ones pattern ('0xFFFFFFFF'), but set the gray with a 24-bit RGB pattern ('0xF2F2F2'). Is there a format mismatch there? I really had no idea, what was I doing there. So I asked. But I did some experiments & this is almost final result with 2 little problems. 1) its slow. I mean it! it takes almost 30sec to replace those pixels. 2) for now it works only with screen capturing, but since its so slow how can i make it replace the pixels in existing file? Im pretty sure I need to change only 1 or 2 lines. but I cant figure it out. aa 1 more thing I will also need to find out file dimensions / height / width. I havent seen any function like that around. does autoit have something like filegetHeight function? I also tried to convert my jpg image to bmp manually & it still wont work. I tried to use: this line instead of screen capture line, but it wont create the image for some reason.: $hBMP = _GDIPlus_BitmapCreateFromFile('Berserk v10c05p109 copy.jpg') Working Code with screen capture: expandcollapse popup#include <GDIPlus.au3> #include <ScreenCapture.au3> $_width = 200 $_height = 200 ; Capture upper left corner of screen $hBMP = _ScreenCapture_Capture("", 0, 0, @DesktopWidth, @DesktopHeight) _GDIPlus_Startup() ;~ $hBMP = _GDIPlus_BitmapCreateFromFile('Berserk v10c05p109 copy.jpg') $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) ;## replace pixel color hire For $line = 0 To $_height Step 1 For $col = 0 To $_width Step 1 $var = PixelGetColor( $col , $line ) If Hex($var, 6) = 'FFFFFF' Then _GDIPlus_BitmapSetPixel($hBitmap, $col, $line, 0xFFF2F2F2) Next Next _GDIPlus_ImageSaveToFile($hBitmap, "test.bmp") ShellExecute('test.bmp') ; Clean up resources _GDIPlus_ImageDispose($hBitmap) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() Func _GDIPlus_BitmapSetPixel($hBitmap, $iX, $iY, $iArgb) Local $aRet $aRet = DllCall($ghGDIPDll, "int", "GdipBitmapSetPixel", "hwnd", $hBitmap, "int", $iX, "int", $iY, "dword", $iArgb) Return EndFunc ;==>_GDIPlus_BitmapSetPixel Edited January 4, 2009 by goldenix My Projects:[list][*]Guide - ytube step by step tut for reading memory with autoitscript + samples[*]WinHide - tool to show hide windows, Skinned With GDI+[*]Virtualdub batch job list maker - Batch Process all files with same settings[*]Exp calc - Exp calculator for online games[*]Automated Microsoft SQL Server 2000 installer[*]Image sorter helper for IrfanView - 1 click opens img & move ur mouse to close opened img[/list] 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