Dreamfire Posted December 1, 2008 Share Posted December 1, 2008 hi,when i try this script on something it work like a charm, however the Top coordinates are not right.it should be something like 220-240 only what i get is more than double that amount. (620-640)Am i doing something wrong or is there a solution for this.I am searching in "SCREEN" and are using $c16RGBPArtialMatch.Regards,Dreamfire Link to comment Share on other sites More sharing options...
junkew Posted December 1, 2008 Author Share Posted December 1, 2008 Fixed the top/left it was a bug (still I have some doubts if I am 100% accurate but its much closer then before) Added functionality to also use window special descriptions. Most usefull one [ACTIVE] to search on the active screen. Performance is not a one choice for 24 bits or 16 bits picture. At least on my machine it seems to differ based on size of pictures searched and beeing searched in. Some speed information. Matchtype 2 (24 bits) is some times faster then matchtype 4 (16 bits). No real explanation for that. Same applies for matchtype 1 and 3 Also using SCREEN is not allways the fastest sometimes smarter to save a screen snapshot once to a file Saving to file should be added to the measurements in the findtester routine Saving calculator window 288.86252439383 milliseconds Saving backspacebutton 12.5010265458337 milliseconds Saving full screen took 153.524945197423 milliseconds True;11;0;0;1280;1024;-1;-1 FULLSCREEN.bmp in FULLSCREEN.bmp ** matchtype 2 time elapsed: 1314.93867725292 milliseconds True;11;0;0;1280;1024;-1;-1 FULLSCREEN.bmp in FULLSCREEN.bmp ** matchtype 4 time elapsed: 1004.20996270751 milliseconds True;260;223;341;260;260;-1;-1 CALCULATOR.bmp in SCREEN ** matchtype 1 time elapsed: 5273.53836314059 milliseconds True;11;223;341;260;260;-1;-1 CALCULATOR.bmp in SCREEN ** matchtype 2 time elapsed: 818.043953003449 milliseconds True;260;223;341;260;260;-1;-1 CALCULATOR.bmp in SCREEN ** matchtype 3 time elapsed: 3967.7225746518 milliseconds True;11;223;341;260;260;-1;-1 CALCULATOR.bmp in SCREEN ** matchtype 4 time elapsed: 1005.02662202262 milliseconds True;260;223;341;260;260;-1;-1 CALCULATOR.bmp in FULLSCREEN.bmp ** matchtype 3 time elapsed: 3789.42262544444 milliseconds True;11;223;341;260;260;-1;-1 CALCULATOR.bmp in FULLSCREEN.bmp ** matchtype 4 time elapsed: 1000.2827585746 milliseconds True;29;48;86;72;29;-1;-1 BACKSPACE.bmp in CALCULATOR.bmp ** matchtype 1 time elapsed: 75.4638089127703 milliseconds True;11;48;86;72;29;-1;-1 BACKSPACE.bmp in CALCULATOR.bmp ** matchtype 2 time elapsed: 48.4907664340899 milliseconds True;29;48;86;72;29;-1;-1 BACKSPACE.bmp in CALCULATOR.bmp ** matchtype 3 time elapsed: 49.6071203250728 milliseconds True;11;48;86;72;29;-1;-1 BACKSPACE.bmp in CALCULATOR.bmp ** matchtype 4 time elapsed: 51.0900259309755 milliseconds True;29;48;86;72;29;-1;-1 BACKSPACE.bmp in [ACTIVE] ** matchtype 1 time elapsed: 51.1056246157136 milliseconds True;11;48;86;72;29;-1;-1 BACKSPACE.bmp in [ACTIVE] ** matchtype 2 time elapsed: 48.0412783703585 milliseconds True;29;48;86;72;29;-1;-1 BACKSPACE.bmp in [ACTIVE] ** matchtype 3 time elapsed: 61.3198666025076 milliseconds True;11;48;86;72;29;-1;-1 BACKSPACE.bmp in [ACTIVE] ** matchtype 4 time elapsed: 39.1093070815623 milliseconds True;29;271;427;72;29;-1;-1 BACKSPACE.bmp in SCREEN ** matchtype 1 time elapsed: 1215.79646723875 milliseconds True;11;271;427;72;29;-1;-1 BACKSPACE.bmp in SCREEN ** matchtype 2 time elapsed: 893.445686636191 milliseconds True;29;271;427;72;29;-1;-1 BACKSPACE.bmp in SCREEN ** matchtype 3 time elapsed: 969.92404229155 milliseconds True;11;271;427;72;29;-1;-1 BACKSPACE.bmp in SCREEN ** matchtype 4 time elapsed: 765.817582270698 milliseconds True;51;0;0;30;51;-1;-1 SEVEN_BW.bmp in 7WDS_BW.bmp ** matchtype 3 time elapsed: 74.4539404389553 milliseconds True;10;0;0;30;51;-1;-1 SEVEN_BW.bmp in 7WDS_BW.bmp ** matchtype 4 time elapsed: 22.2999946534071 milliseconds True;1;90;0;30;29;2;0 CAT_BW.bmp in 7WDS_BW.bmp ** matchtype 3 time elapsed: 55.9600830058545 milliseconds True;1;90;0;30;29;2;0 CAT_BW.bmp in 7WDS_BW.bmp ** matchtype 4 time elapsed: 103.01587537092 milliseconds True;14;224;157;6;14;-1;-1 AUTOIT3.bmp in FULLSCREEN.bmp ** matchtype 1 time elapsed: 1005.85675408346 milliseconds True;8;224;157;6;14;-1;-1 AUTOIT3.bmp in FULLSCREEN.bmp ** matchtype 2 time elapsed: 886.326859945999 milliseconds True;14;224;157;6;14;-1;-1 AUTOIT3.bmp in FULLSCREEN.bmp ** matchtype 3 time elapsed: 714.427910551501 milliseconds True;8;224;157;6;14;-1;-1 AUTOIT3.bmp in FULLSCREEN.bmp ** matchtype 4 time elapsed: 638.65006014917 milliseconds FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
mortelrdv Posted December 18, 2008 Share Posted December 18, 2008 Hello,Sorry, i'm new user of Autoit.How can i use this function ?by "#include" or just copy the script in my script ?if i must use "#include", you should not include to declare a variable, a constant ??????; Syntax: findBMP($BMP1, $BMP2, $MatchType=TRUE);; Parameter(s): $BMP1 = Filename of bitmap to search in; $BMP2 = Filename of bitmap to search for; $MatchType = c24RGBFullMatch, c24RGBPartialMatch, c16RGBFullMatch, c16RGBPartialMatchsorry for my poor english, i'm french Link to comment Share on other sites More sharing options...
Zedna Posted December 18, 2008 Share Posted December 18, 2008 Hello,Sorry, i'm new user of Autoit.How can i use this function ?by "#include" or just copy the script in my script ?if i must use "#include", you should not include to declare a variable, a constant ??????sorry for my poor english, i'm frenchJust copy function declaration into your script. Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
ferrix Posted December 29, 2008 Share Posted December 29, 2008 This is the coolest script ever. It is incredibly helpful for automating remote machines or odd controls where you only have images of what is going on instead of actual standard window controls. I am putting together a tool kit of functions used in my application testing on VMware guest machines. The "VIX" sdk is extremely limited in what it can do. Combined with AutoIt, findBMP, and AU3Recorder, I shall be unstoppable! Link to comment Share on other sites More sharing options...
Armand Posted December 30, 2008 Share Posted December 30, 2008 (edited) @ferrixlol mate B.T.W - can it already solve the mystery i've posted on the first page ?!?ummzz....not quit accurate working.... try finding pic A inside pic B in these:A.B.Could be very useful if it could work on such pictures... Edited December 30, 2008 by Armand [u]My Au3 Scripts:[/u]____________(E)Lephant, A Share download manager (RS/MU etc)Http1.1 Console, The Ez Way!Internet Reconnection Automation Suite & A Macro Recording Tool.SK's Alarm Clock, Playing '.MP3 & .Wav' Files._________________Is GOD a mistake of the Humanity Or the Humanity is a mistake of GOD ?! Link to comment Share on other sites More sharing options...
junkew Posted December 30, 2008 Author Share Posted December 30, 2008 Yes, it can partly recognize those pictures. See the thread where I answered partly your problem.But there are definitely limitations and you have to modify the code yourself and reuse the principle on how I match pictures.Use the combination of the return value$bMatchPossible = Could a match be possible$matchedLines = The number of matched lines (if its 1 previous returnvalue probably better to set it at FalseCorrect syntaxfindBMP($Image1,$Image2,$c24RGBFullMatch) findBMP($Image1,$Image2,$c24RGBPartialMatch) findBMP($Image1,$Image2,$c16RGBFullMatch) findBMP($Image1,$Image2,$c16RGBPartialMatch)Small attention point is in the code: It doesn't return true or false based on if it has found the picture. It depends on the other values returned.If just 1 line of the picture matches it returns true.I think an enhancement could be to add an if statement in the findBMP.if $matchedLines=1 then $bMatchPossible=False (but on the other hand if the picture is 1 line high it also returns a false negative).The returned values are$bMatchPossible = Could a match be possible$matchedLines = The number of matched lines (if its 1 previous returnvalue probably better to set it at False$foundAtLeft $foundAtTop $bmp2width $BMP2Height $HighestMatchingLines $bestMatchLineThere is definitely a bug/attention point on 2 color bitmaps and alignment on boundaries. If you have problems with certain pictures try to increase or decrease width and height of your picture (trial and error, sorry for that)One of those problematic areas is shown in threadhttp://www.autoitscript.com/forum/index.php?showtopic=86784 FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
ferrix Posted January 6, 2009 Share Posted January 6, 2009 I made an additional function and some small changes to the findBMP for my needs.My added functionality is to screen capture the image of a non-active window (i.e. something that is a background window, and not necessarily fully visible). This uses the PrintWindow() windows user32 function available in XP/2003 and later. Individual apps may not support it correctly, but most do. Particularly vmware workstation, which is what I need this for.NOTE: If the window is minimized, then this will NOT work; the PrintWindow function can't get an image of a window that's minimized.Here is the new function. You can use it in a stand-alone script similar to the _ScreenCapture_CaptureWnd function, except it works on background windows too expandcollapse popup#include-once #include <winapi.au3> ; by ferrix. ; similar to the _Screencapture functions, ; you must delete the returned HDC by using _WinAPI_DeleteObject Func CaptureWindowBitmap($hwnd) local $h = _WinAPI_GetWindowHeight($hwnd) local $w = _WinAPI_GetWindowWidth($hwnd) local $hDC = _WinAPI_GetWindowDC($hwnd) if not $hDC then MsgBox(0, "hDC", _WinAPI_GetLastError()) return 0 EndIf local $hdcMem = _WinAPI_CreateCompatibleDC($hDC) if not $hdcMem then MsgBox(0, "hdcMem", _WinAPI_GetLastError()) return 0 EndIf local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $w, $h) if not $hBmp then MsgBox(0, "hBmp", _WinAPI_GetLastError()) return 0 EndIf local $hOld = _WinAPI_SelectObject($hdcMem, $hBmp) _WinAPI_SetLastError(0) $ret = DllCall("User32.dll", "int", "PrintWindow", "hwnd", $hwnd, "ptr", $hdcMem, "uint", 0) if @error or _WinAPI_GetLastError() or (not $ret[0]) then MsgBox(0, "Error", @error & " " & _WinAPI_GetLastError()) _WinAPI_SelectObject($hdcMem, $hOld) _WinAPI_DeleteObject($hdcMem) _WinAPI_ReleaseDC($hwnd, $hDC) Return $hBmp EndFuncPlease be gentle, I am a brand new AutoIt user and I don't know all the details about making a real UDF yet. Is there a udf-making faq or instructions?Here are the changes to findBMP that are needed to support my functionality. With these changes, you pass the first argument as an hwnd (get that by WinGetHandle!). findBMP then detects the argument is a hwnd instead of a filename, and uses that window's region as the image search area.; Load the bitmap to search in If $BMPFile="SCREEN" Then $hbScreen=_ScreenCapture_Capture("",0,0,-1,-1,False) $pBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbScreen); returns memory bitmap _WinAPI_DeleteObject($hbScreen) ; ***** BEGIN CHANGES ***** ElseIf IsHWnd($BMPFile) Then $hbWindow = CaptureWindowBitmap($BMPFile) _WinAPI_DeleteObject($hbWindow) ; ***** END CHANGES ***** Else ;try to get a handleHope this is useful either inside findBMP or standalone. Just my thanks for all the great functionality available by junkew and everyone on this board I am using this right now to wait until a VM is at the Logon screen and then alert me. This way I don't have to keep checking it and I can work on something else in the foreground. Link to comment Share on other sites More sharing options...
junkew Posted February 20, 2009 Author Share Posted February 20, 2009 Fixed a bug now matching much better on black/white pictures line fixed: $iPos = StringInStr($BMP1Data, $searchFor, 2, 1, $iPos) FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Zedna Posted February 21, 2009 Share Posted February 21, 2009 Please be gentle, I am a brand new AutoIt user and I don't know all the details about making a real UDF yet. Is there a udf-making faq or instructions?It's here:http://www.autoitscript.com/forum/index.ph...st&p=465001 Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search Link to comment Share on other sites More sharing options...
trinitrotoluen Posted April 3, 2009 Share Posted April 3, 2009 (edited) Can you please tell me what your example want to do ? I tested it and there was an error : >"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "F:\Thang2\SOFT\PROGRAMMING\AutoIT\AutoIT - My work\t.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams +>06:13:32 Starting AutoIt3Wrapper v.1.10.1.14 Environment(Language:0409 Keyboard:00000409 OS:WIN_XP/Service Pack 3, v.5657 CPU:X86 ANSI) >Running AU3Check (1.54.14.0) from:C:\Program Files\AutoIt3 +>06:13:32 AU3Check ended.rc:0 >Running:(3.3.0.0):C:\Program Files\AutoIt3\autoit3.exe "F:\Thang2\SOFT\PROGRAMMING\AutoIT\AutoIT - My work\t.au3" Saving calculator window 507.28772375709 milliseconds F:\Thang2\SOFT\PROGRAMMING\AutoIT\AutoIT - My work\t.au3 (51) : ==> Subscript used with non-Array variable.: _ScreenCapture_Capture($Bitmap3Filename, ($aWinPos[0]+$pos[0]) + ($aWinPos[2] - $aWinCSize[0])-3, ($awinpos[1]+$pos[1])+ ($aWinPos[3]-$aWinCSize[1])-3, $aWinPos[0]+$pos[0]+$pos[2]+3, ($awinpos[1]+$pos[1])+ ($aWinPos[3]-$aWinCSize[1])+$pos[3]-3,false) _ScreenCapture_Capture($Bitmap3Filename, ($aWinPos[0]+$pos^ ERROR ->06:13:35 AutoIT3.exe ended.rc:1 +>06:13:36 AutoIt3Wrapper Finished >Exit code: 1 Time: 4.143 Well, After I changed BACKSPACE to Backspace it showed "error locking region 2". How can I slove that ? Edited April 3, 2009 by trinitrotoluen Link to comment Share on other sites More sharing options...
BurninSun Posted April 24, 2009 Share Posted April 24, 2009 I've been trying to get this to work for hours now, but all it ever returns is false. First I made a file called ImageSearch.au3 and put in #include <GDIPlus.au3> #Include <ScreenCapture.au3> const $c24RGBFullMatch=1 ;Load as 24 bits and full match const $c24RGBPartialMatch=2 ;Load as 24 bits and partial match const $c16RGBFullMatch=3 ;Load as 16 bits and full match const $c16RGBPartialMatch=4 ;Load as 16 bits and partial match followed by a complete copy/paste of the 2nd script (I've also tried directly embedding the code into mine with the same result) I downloaded the attached pics and ran this: #include "ImageSearch.au3" _GDIPlus_Startup() $imgInfo = FindBMP("D:\pics\Calculator.bmp", "D:\pics\backspace.bmp", $c24RGBFullMatch) ConsoleWrite($imginfo) _GDIPlus_Shutdown() In the console, I get False;0;-1;-1;72;29;-1;-1 I've tried a few combinations of the attached bitmaps, I've tried comparing files with themselves, and I've tried all the various arguments for the 3rd parameter and all return false. Any ideas? Autoit 3.3.0.0 Windows XP Pro SP3 Link to comment Share on other sites More sharing options...
BurninSun Posted April 25, 2009 Share Posted April 25, 2009 Fixed $iPos is initialized as 0 so the first iteration sends a 0 as the search start parameter for StringInStr which then fails. Initializing $iPos to 1 fixes the problem. Link to comment Share on other sites More sharing options...
junkew Posted May 2, 2009 Author Share Posted May 2, 2009 Fixed$iPos is initialized as 0 so the first iteration sends a 0 as the search start parameter for StringInStr which then fails.Initializing $iPos to 1 fixes the problem.Added the fix to the initial source code posting FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
wagner1308 Posted May 29, 2009 Share Posted May 29, 2009 this is neat, good work!Good afternoon, I need to do something like this your exmple, I need compare two images, which are prints screens. I tried to run your code, but it did not work. you can help me? Link to comment Share on other sites More sharing options...
wagner1308 Posted May 29, 2009 Share Posted May 29, 2009 Good afternoon, I need to do something like this your exmple, I need compare two images, which are prints screens. I tried to run your code, but it did not work. you can help me? Link to comment Share on other sites More sharing options...
Developers Jos Posted May 29, 2009 Developers Share Posted May 29, 2009 (edited) It normally helps when you put some effort in describing what your problem is and show some code, because a vague description like this normally gets not attention. Also don't really know what that second post is for? Jos Edited May 29, 2009 by Jos SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
scheiny Posted September 29, 2009 Share Posted September 29, 2009 Hi all,thanks junkew for this solution!However shouldn't it read$iPos = StringInStr($BMP1Data, $searchFor, *1*, 1, $iPos)for a case-sensitive comparison?Wouldn't a case-insensitive comparison lead to false positives?I modified the first post and included the samples you gave to work with. You can work with black and white pictures as long as you store them as 24 bits bitmap.With monochrome bitmaps the algorithm will only work if you align on 8 bits (which then becomes a byte and then it will work as algorithm is based on byte boundaries) but still its tricky as the picture you are searching in should also be on an 8 bits boundary.The "problem" with monochrome is that each pixel is bit encoded and as such 8 pixels are in a byte whereas in a 24 color bitmap you have 3 bytes for 1 pixel.If you want to find a monochrome bmp on a 24 bmp colored screen I would suggest to first convert it to a 24 bits color bitmap.To be able to do 2 color bitmap searching I have to shift each string each time 8 times and compare it 8 times with a shifted string of the picture to search in.Imagine that you want to find 00010001 on a screen of 32 pixels width which is 4 bytes like 00000001 00010000 00000000 10010000I then would have to shift like below 00010001shift 1: 00000010 00100000 00000001 00100000 would not match as the matching string is over the first 2 bytesshift 2: 00000100 01000000 00000010 01000000 would not match as the matching string is over the first 2 bytesshift 3: 00001000 10000000 00000100 10000000 would not match as the matching string is over the first 2 bytesshift 4: 00010001 00000000 00001001 00000000 would matchIncorporating that kind of logic is making it much more complicated then to switch to a getPixel algorithmThanks for this wonderful piece of software.My question is shouldn't Link to comment Share on other sites More sharing options...
junkew Posted December 13, 2009 Author Share Posted December 13, 2009 Based on a request I received I made below straightforward but slow algorithm to compare if anything on screen has changed. More optimized variants could be 1. use bitblt functions 2. Use code like below but do a upper/half (recursive) comparison method (binary split each time taking both halves of a part screen like) if $bmp1Data<>$bmp2Data then if StringMid($BMP1Data,$bmp1Height/2) = StringMid($BMP2Data,$bmp2Height/2) then ... 'First half = equal ... expandcollapse popup; Opt('MustDeclareVars', 1) ;#include <GUIConstants.au3> #include <GDIPlus.au3> #include <ScreenCapture.au3> #include <string.au3> ;~ Constants for type of picture matching Const $c24RGBFullMatch = 1 ;Load as 24 bits and full match Const $c24RGBPartialMatch = 2 ;Load as 24 bits and partial match Const $c16RGBFullMatch = 3 ;Load as 16 bits and full match Const $c16RGBPartialMatch = 4 ;Load as 16 bits and partial match Global $Bitmap1Filename = @tempdir & "\FULLSCREEN.BMP" ;Full screen to search in Global $Bitmap2Filename = @tempdir & "\FULLSCREEN2.BMP" ;Full screen to compare with ; Initialize GDI+ library _GDIPlus_Startup() _ScreenCapture_Capture($Bitmap1Filename, 0, 0, -1, -1, False) ;Make sure something changes ConsoleWrite("Changing lines " & @LF) sleep(2000) ; Wait 2 seconds to have the screen changing _ScreenCapture_Capture($Bitmap2Filename, 0, 0, -1, -1, False) comparebmp($Bitmap1Filename,$Bitmap2Filename) _GDIPlus_Shutdown() Func compareBMP($BMP1, $BMP2, $MatchType = $c24RGBFullMatch) Dim $BMP1Data = "", $BMP1Width = 0, $BMP1Height = 0, $BMP1LineWidth = 0, $padBytes1 Dim $BMP2Data = "", $BMP2Width = 0, $BMP2Height = 0, $BMP2LineWidth = 0, $padBytes2 Dim $TDiffString ="" If ($MatchType = $c24RGBFullMatch) Or ($MatchType = $c24RGBPartialMatch) Then $imgBytes = 3 Else $imgBytes = 2 EndIf ; Load the bitmap to search in GetImage($BMP1, $BMP1Data, $BMP1Width, $BMP1Height, $BMP1LineWidth, $imgBytes) $BMP1Data = BinaryToString($BMP1Data) ; Load the bitmap to find GetImage($BMP2, $BMP2Data, $BMP2Width, $BMP2Height, $BMP2LineWidth, $imgBytes) ;Make it strings to be able to use string functions for searching $BMP2Data = BinaryToString($BMP2Data) ;Determine bytes used for padding on 4 byte boundary $padBytes1 = $BMP1LineWidth - ($BMP1Width * $imgBytes) $padBytes2 = $BMP2LineWidth - ($BMP2Width * $imgBytes) ;Straight forward compare $tBeginTime = TimerInit() for $i=0 to $BMP2Height-1 if StringMid($BMP1Data, 1 + ($i * $BMP1LineWidth), ($BMP1LineWidth - $padBytes1)) <>StringMid($BMP2Data, 1 + ($i * $BMP2LineWidth), ($BMP2LineWidth - $padBytes2)) Then $TDiffString =$TDiffString & $i & ";" endif Next ConsoleWrite("Differences on line " & $TDiffString & @LF) ConsoleWrite("Comparison took " & TimerDiff($tBeginTime) & " milliseconds " & @LF) endfunc Func GetImage($BMPFile, ByRef $BMPDataStart, ByRef $Width, ByRef $Height, ByRef $Stride, $imgBytes = 3) Local $Scan0, $pixelData, $hbScreen, $pBitmap, $pBitmapCap, $handle ; Load the bitmap to search in If $BMPFile = "SCREEN" Then $hbScreen = _ScreenCapture_Capture("", 0, 0, -1, -1, False) $pBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbScreen) ; returns memory bitmap Else ;try to get a handle $handle = WinGetHandle($BMPFile) If @error Then ;Assume its an unknown handle so correct filename should be given $pBitmap = _GDIPlus_BitmapCreateFromFile($BMPFile) Else $hbScreen = _ScreenCapture_CaptureWnd("", $handle, 0, 0, -1, -1, False) $pBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hbScreen) ; returns memory bitmap EndIf EndIf ;Get $tagGDIPBITMAPDATA structure ;~ ConsoleWrite("Bitmap Width: " & _GDIPlus_ImageGetWidth($pBitmap) & @CRLF ) ;~ ConsoleWrite("Bitmap Height: " & _GDIPlus_ImageGetHeight($pBitmap) & @CRLF) ;~ 24 bits (3 bytes) or 16 bits (2 bytes) comparison If ($imgBytes = 2) Then $BitmapData = _GDIPlus_BitmapLockBits($pBitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $GDIP_PXF16RGB555) Else $BitmapData = _GDIPlus_BitmapLockBits($pBitmap, 0, 0, _GDIPlus_ImageGetWidth($pBitmap), _GDIPlus_ImageGetHeight($pBitmap), $GDIP_ILMREAD, $GDIP_PXF24RGB) EndIf 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("ubyte lData[" & (Abs($Stride) * $Height - 1) & "]", $Scan0) $BMPDataStart = $BMPDataStart & DllStructGetData($pixelData, "lData") _GDIPlus_BitmapUnlockBits($pBitmap, $BitmapData) _GDIPlus_ImageDispose($pBitmap) _WinAPI_DeleteObject($pBitmap) EndFunc ;==>GetImage FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
MasonMill Posted July 9, 2010 Share Posted July 9, 2010 Anyone know why you get Error locking region 2? 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