VAG Posted June 3, 2010 Share Posted June 3, 2010 I would like to know is there a command in AutoIT to do Bitmap.GetPixel? I can only found PixelGetColor() which is for onscreen pixel but not bmp file. I need to read the color directly without using methods like _GDIPlus_BitmapCreateFromFile() then Draw it on screen to read the pixel.Here is the .Net method I'm refering:http://msdn.microsoft.com/en-us/library/system.drawing.bitmap.getpixel.aspx Link to comment Share on other sites More sharing options...
AndyG Posted June 3, 2010 Share Posted June 3, 2010 Hi, something written quick and dirty...expandcollapse popup#include <GDIPlus.au3> #include <GDIPlusConstants.au3> #include <ScreenCapture.au3> _ScreenCapture_Capture("pic.jpg") $t = TimerInit() $color=_GetPixelFromBMP("pic.jpg",100,100) ;Rückgabe: Farbe in BGR Input: file, umd die Koordinaten x und y ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $color = ' & $color & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console $m = TimerDiff($t) ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : time = ' & $m & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console Func _GetPixelFromBMP($sImage,$x,$y );git die farbe an $x,$y einer 24bpp-bitmap aus Local $pbitmap, $Bmp Local $tBD, $iWidth, $iHeight, $iStride Local $pData, $color _GDIPlus_Startup() $pbitmap = _GDIPlus_ImageLoadFromFile($sImage) ;bild laden If @error Then Return SetError(1, 2, 0) $tBD = _GDIPlus_BitmapLockBits($pbitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $GDIP_PXF24RGB) If @error Then MsgBox(0, "", "Error locking region " & @error) $iWidth = DllStructGetData($tBD, 1) ;breite der bitmap $iHeight = DllStructGetData($tBD, 2) ;hoehe der bitmap $iStride = DllStructGetData($tBD, 3) ;Erklärung : http://www.autoitscript.com/forum/index.php?showtopic=106673&view=findpost&p=753169 $pData = DllStructGetData($tBD, 5) ;pointer auf die bitmapdaten $Bmp = DllStructCreate("byte[" & $iStride * $iHeight & "]", $pData) ;struct gefüllt mit den Daten der Bitmap $position = $istride * ($y - 1) + 3 * ($x-1) ;Umrechnung der Position von x- und y- Koordinaten $substruct = DllStructCreate("ubyte[3]", DllStructGetPtr($Bmp) + $position) ;eine 3-byte struct an die position vom pixel schreiben $Color = DllStructgetData($substruct, 1) ;Daten aus der struct lesen _GDIPlus_BitmapUnlockBits($pbitmap, $tBD) ;_WinAPI_DeleteObject($hBmp) _GDIPlus_ImageDispose($pbitmap) _GDIPlus_Shutdown() return $color EndFunc ;==>_GetImagePixels If you know the bpp of your bitmap, there is a much faster way. Open the file as binary and read the BGR-bytes(=colour) via stringmid(). This takes only a view milliseconds... Link to comment Share on other sites More sharing options...
VAG Posted June 4, 2010 Author Share Posted June 4, 2010 Thanks for the quick respond. I was also thinking of using Dllstruct, but I'm not familiar with it. I will try to study on it....Thankyou Link to comment Share on other sites More sharing options...
Yashied Posted June 4, 2010 Share Posted June 4, 2010 Use _GDIPlus_BitmapGetPixel() from GDIP.au3. My UDFs: iKey | FTP Uploader | Battery Checker | Boot Manager | Font Viewer | UDF Keyword Manager | Run Dialog Replacement | USBProtect | 3D Axis | Calculator | Sleep | iSwitcher | TM | NetHelper | File Types Manager | Control Viewer | SynFolders | DLL Helper Animated Tray Icons UDF Library | Hotkeys UDF Library | Hotkeys Input Control UDF Library | Caret Shape UDF Library | Context Help UDF Library | Most Recently Used List UDF Library | Icons UDF Library | FTP UDF Library | Script Communications UDF Library | Color Chooser UDF Library | Color Picker Control UDF Library | IPHelper (Vista/7) UDF Library | WinAPI Extended UDF Library | WinAPIVhd UDF Library | Icon Chooser UDF Library | Copy UDF Library | Restart UDF Library | Event Log UDF Library | NotifyBox UDF Library | Pop-up Windows UDF Library | TVExplorer UDF Library | GuiHotKey UDF Library | GuiSysLink UDF Library | Package UDF Library | Skin UDF Library | AITray UDF Library | RDC UDF Library Appropriate path | Button text color | Gaussian random numbers | Header's styles (Vista/7) | ICON resource enumeration | Menu & INI | Tabbed string size | Tab's skin | Pop-up circular menu | Progress Bar without animation (Vista/7) | Registry export | Registry path jumping | Unique hardware ID | Windows alignment More... 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