Sign in to follow this  
Followers 0
timmalos

Check image on screen and get closest one from library

3 posts in this topic

Hello all.

I'm trying to do something simple, but I can't manage to find where to start since I can have multiple possibilities and not sure what is the best one :

  1. Taking screen capture (I can do that)
  2. On this capture, I'll look for 10 particular regions that will give me 10 images of 40px * 40px (I can do that)
  3. Then what I want is for each of these regions, find on my library of ~140 images which one is the closest one to my region (= the match)

 

What do you think is the best approach ? Ican easily do step 1 and 2, however for the third step :

  • I can't use memcmp because they won't be exactly the same (original library can differ a very little bit from what I'll get from my screen capture)
  • There is no text, only drawing
  • Should I do a pixelSum of what I get on screen and do the same via GDIPlus for each of my images in the library?

 

Thanks a lot,

Tim

 

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Tried this ;

And this :

Without a lot of success, bot scripts fail for different reason and are quite old.

Edited by timmalos

Share this post


Link to post
Share on other sites
1 hour ago, timmalos said:

I'm trying to do something simple

Errm, no, not at all. Image recognition and interpretation is computationally very hard, otherwise companies wouldn't be spending hundreds of millions of dollars on developing better algorithms (self-learning, AI, PCA) to do something you take for granted such as distinguishing between the faces of your family members, for example.

That said, here are some simple suggestions, or you could use ImageMagick's compare functionality.

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • TheNorwegianUser
      Screencapture display "error"
      By TheNorwegianUser
      I don't get why the images I take turns up like this, but it seems to me like the screenshot doesn't go from the actual positions specified. It's weird, cause what happends is that when I for example move the mouse over the number 25 on SciTE, the image shows that it's over 19... Anyone knows what I'm doing wrong?
      #include <screencapture.au3> #include <WindowsConstants.au3> Hotkeyset("{ESC}", "Terminate") $gui = GUICreate("", 100, 800, 100, 0, $WS_POPUP, $WS_EX_TOPMOST) _GDIPlus_Startup() $graphics = _GDIPlus_GraphicsCreateFromHWND($gui) GUISetState(@SW_SHOW, $gui) While 1 $scr = _ScreenCapture_Capture("", 0, 0, 100, 800) $bitmap = _GDIPlus_BitmapCreateFromHBITMAP($scr) _WinAPI_DeleteObject($scr) _GDIPlus_GraphicsDrawImage($graphics, $bitmap, 0, 0) WEnd Func Terminate() _GDIPlus_GraphicsDispose($graphics) _GDIPlus_BitmapDispose($bitmap) _GDIPlus_Shutdown() Exit EndFunc  
    • LegitStack
      ScreenCapture 4k res - how to get dpi awareness?
      By LegitStack
      Been struggling with this one for a while. 
      when I do a _screencapture_capture call on a high resolution monitor (like my surface book) it gives me an image that has 2 problems:
      1. its in the wrong location on the screen
      and
      2. it gives me a picture that is larger than the area of the screen I selected, though it only has the content of what I selected. 
      ---------------------------
      I was able to easily fix problem #1 by manually adjusting the x y coordinates to compensate for the amount of DPI scale I have.
      for instance if I'm 200% zoomed in the code looks like this:
      Local $bmp = _ScreenCapture_Capture("", $iX1*2, $iY1*2, $iX2*2, $iY2*2, false)  it's problem #2 that is the big problem. I'd like to attach a screen shot of what I'm talking about (see capture.png)

      ---------------------------
      Now I basically understand why this is happening. ScreenCapture grabs each pixel of the screen. This screen, being a high resolution, when its zoomed in adds up several pixels to make one on the screen. 
      This is a problem for me because I'm taking images of the screen and later looking for those exact images on the screen. if everything is blown up by an indeterminate amount (in my case 2x) then those images can't be found later on. 
      Does anyone know what I can do? 
      I tried resizing the images back down to no avail. 
      _GDIPlus_ImageResize and _GDIPlus_ImageScale don't work because they don't compress the pixels correctly. quality is lost. and the exact image isn't preserved, so I can't search for it later. (see capture1.png)

       
      Anyway, I'm about to give up, been on this problem for too long! does anyone know what I can do? Seems to me that the ideal solution would be to eventually have autoit add an argument to _screencapture_capture that lets you specify a DPI scale amount or something.  that can be pulled from the registry at HKEY_CURRENT_USER\control panel\desktop\windowmetrics\appliedDPI.
      But in the meantime, does anyone have any suggestions for how I can make my program compatible with 4k resolution monitors? I either need to take the screen capture like normal, then scale it down appropriately without losing quality, or I need to capture the screen in the first place like the human sees it. But I don't know how to do that either. 
      I'll post my relevant code here: (in my project I call ScreenCapture_DPI_Aware)
      #include <Security.au3> Func _GetAppliedDPI()   Local $aArrayOfData = _Security__LookupAccountName(@UserName)   If IsArray($aArrayOfData) Then   ;msgbox(64, "SID String = ", $aArrayOfData[0] & @CRLF)   ;msgbox(64, "Domain name = ", $aArrayOfData[1] & @CRLF)   ;msgbox(64, "SID type = ", _Security__SidTypeStr($aArrayOfData[2]) & @CRLF)     ;Local $AppliedDPI = RegRead("HKEY_USERS\" & $aArrayOfData[0] & "\Control Panel\Desktop\WindowMetrics", "AppliedDPI") Local $AppliedDPI = RegRead("HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics", "AppliedDPI")     return $AppliedDPI   EndIf EndFunc Func GetScale()   $applied = _GetAppliedDPI()   if $applied == "" then     return 1   else     return $applied / 96   EndIf EndFunc Func ScreenCapture_Capture_DPI_Aware($sBMP_Path, $iX1, $iY1, $iX2, $iY2, $bool)   $R = GetScale() ;Raito   Local $bmp = _ScreenCapture_Capture($sBMP_Path, $iX1*$R, $iY1*$R, $iX2*$R, $iY2*$R, $bool) ;Scaling didn't work: ;_ScaleImage($bmp, $sBMP_Path, abs($iX2 - $iX1), abs($iY2 - $iY1), $R)   ;return _ScreenCapture_Capture($sBMP_Path, $iX1*$R, $iY1*$R, $iX2*$R, $iY2*$R, $bool) EndFunc ;Func _ScaleImage($bmp, $outimage, $w, $h, $scale) ; _GDIPlus_Startup() ;Get the encoder of to save the resized image in the format you want. ; Local $Ext = StringUpper(StringMid($outimage, StringInStr($outimage, ".", 0, -1) + 1)) ; $CLSID = _GDIPlus_EncodersGetCLSID($Ext) ; code found here : https://www.autoitscript.com/autoit3/docs/libfunctions/_GDIPlus_ImageSaveToStream.htm ; Local $sImgCLSID = _GDIPlus_EncodersGetCLSID("png") ;create CLSID for a JPG image file type ; Local $tGUID = _WinAPI_GUIDFromString($sImgCLSID) ;convert CLSID GUID to binary form and returns $tagGUID structure ; Local $tParams = _GDIPlus_ParamInit(1) ;initialize an encoder parameter list and return $tagGDIPENCODERPARAMS structure ; Local $tData = DllStructCreate("int Quality") ;create struct to set JPG quality setting ; DllStructSetData($tData, "Quality", 100) ;quality 0-100 (0: lowest, 100: highest) ; Local $pData = DllStructGetPtr($tData) ;get pointer from quality struct ; _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) ;add a value to an encoder parameter list ; Local $gbmp = _GDIPlus_BitmapCreateFromHBITMAP($bmp) ; _WinAPI_DeleteObject($bmp) ; Local $gsbmp = _GDIPlus_ImageResize($gbmp, $w * $scale, $h * $scale) ;Local $ext = _GDIPlus_EncodersGetCLSID("PNG") ; _GDIPlus_ImageSaveToFileEx($gsbmp, $outimage, $sImgCLSID) ; _GDIPlus_BitmapDispose($gbmp) ; _GDIPlus_BitmapDispose($gsbmp) ; _GDIPlus_Shutdown() ;EndFunc
      Thanks for any help you can give me!!!
    • GtaSpider
      _GDIPlus_EffectCreateBlur only horizontal?
      By GtaSpider
      Hey everyone,
      When I try to add blur to an Image with _GDIPlus_EffectCreateBlur and _GDIPlus_BitmapApplyEffect the blur is only horizontal, not horizontal and vertical, if the blur radius is <= 20. 
      Easy to test with the Image I attached and the default example from the helpfile of 
      _GDIPlus_BitmapApplyEffect The second Image I attached is the result and as you can see the cross is only blurred in one direction.  Does anyone have a clue why this happens and furthermore a solution for this problem? (I could just rotate the picture but then it would be twice as time consuming...)
      Thanks in advance,
      Spider
      p.s.: Running Win 10 Pro with all updates


    • timmy2
      Trying to display text with a transparent BG atop a Veeblefetzer
      By timmy2
      The following demo script, drawn largely from examples by @UEZ, lets me display colored text over a transparent background using my choice of font, type size, etc.  It is a single function (out of many) in the project I'm scripting, but it is crucial to my goal of displaying messages in an interesting way (IMHO).  
      (For the purpose of this forum post it displays a single string variable; my actual project script reads a number of  possible messages from a text file into an array and then chooses the messages to be displayed based on stuff that happens in the course of someone using my program.)
      Note that I am seeking help only to overcome my inability to figure out how to display this text atop a PNG graphic, and make the result a draggable object.
       
      #cs Display a message one character at a time with the goal of adding a PNG graphic overlay #ce ;~ #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <GUIConstants.au3> Global $sMessage Global $iString = 0 Global $aInfo Global Const $SC_DRAGMOVE = 0xF012 HotKeySet("{Esc}","Close") ; in my actual script I read in a file containing all the text to be displayed Global $sText = _ "Lorem ipsum dolor sit amet, consectetur" & @CRLF & _ "elit, sed do eiusmod tempor incididunt ut" & @CRLF & _ @CRLF & _ "Et dolore magna aliqua. Ut enim ad minim," & @CRLF & _ "quis nostrud exercitation ullamco laboris nisi" & @CRLF & _ "aliquip ex ea commodo consequat." & @CRLF & _ @CRLF & _ "Duis aute irure dolor in reprehenderit in" & @CRLF & _ "voluptate velit esse cillum dolore eu fugiat" & @CRLF & _ "nulla pariatur." & @CRLF ; Create GUI Global $hGUI = GUICreate("", 450, 340, -1, -1, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST)) GUISetBkColor(0xFF000000) ; will change background color, which UEZ doesn't use in his example, but then he doesn't want a BG GUISetState(@SW_SHOW) ; Draw a string _GDIPlus_Startup() Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF99ff33) Global $hFormat = _GDIPlus_StringFormatCreate() Global $hFamily = _GDIPlus_FontFamilyCreate("VT323") Global $hFont = _GDIPlus_FontCreate($hFamily, 14, 0) Global $tLayout = _GDIPlus_RectFCreate(20, 20, 0, 0) Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromScan0(420, 300) Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetTextRenderingHint($hBuffer, 4) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 4) GUIRegisterMsg($WM_LBUTTONDOWN, "_WM_LBUTTONDOWN") For $iString = 1 to StringLen($sText) $sMessage = StringLeft($sText,$iString) $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sMessage, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsClear($hBuffer, 0x000000) _GDIPlus_GraphicsDrawStringEx($hBuffer, $sMessage, $hFont, $aInfo[0], $hFormat, $hBrush) $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_BitmapDisplayTransparentInGUI($hHBitmap, $hGUI) _WinAPI_DeleteObject($hHBitmap) Next Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Close() ; Clean up resources (my best guess at what needs closing/shutting down) Func Close() _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown() Exit EndFunc ;==>Close Func _WinAPI_BitmapDisplayTransparentInGUI(ByRef $hHBitmap, ByRef $hGUI, $iOpacity = 0xFF, $bReleaseGDI = True) If Not BitAND(GUIGetStyle($hGUI)[1], $WS_EX_LAYERED) = $WS_EX_LAYERED Then Return SetError(1, 0, 0) Local $tDim = DllStructCreate($tagBITMAP) If Not _WinAPI_GetObject($hHBitmap, DllStructGetSize($tDim), DllStructGetPtr($tDim)) Then Return SetError(2, 0, 0) Local $tSize = DllStructCreate($tagSIZE), $tSource = DllStructCreate($tagPOINT), $tBlend = DllStructCreate($tagBLENDFUNCTION) Local Const $hScrDC = _WinAPI_GetDC(0), $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC), $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) $tSize.X = $tDim.bmWidth $tSize.Y = $tDim.bmHeight $tBlend.Alpha = $iOpacity $tBlend.Format = 1 _WinAPI_UpdateLayeredWindow($hGUI, $hScrDC, 0, DllStructGetPtr($tSize), $hMemDC, DllStructGetPtr($tSource), 0, DllStructGetPtr($tBlend), $ULW_ALPHA) _WinAPI_ReleaseDC(0, $hScrDC) _WinAPI_SelectObject($hMemDC, $hOld) _WinAPI_DeleteDC($hMemDC) If $bReleaseGDI Then _WinAPI_DeleteObject($hHBitmap) Return True EndFunc Func _WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam) Switch $hWnd Case $hGUI _SendMessage($hWnd, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) EndSwitch EndFunc ;==>_WM_LBUTTONDOWN  
      The above script lets me push the text out to the screen, but I want to display the text atop a PNG graphic, which is an imagined piece of hand-held test equipment that I'll refer to here as the Veeblefetzer.
      Here's a half-size animated gif of the desired result.

       
      Note that initially I used a different script to stream the text out atop a built-in black background rectangle.  I figured I would place the Veeblefetzer graphic above the text -- with the center "display area" of the Veeblefetzer cut out (transparent).  
      Then UEZ's example script came along. The benefit of using text that has a transparent BG, and placing it in a layer above the Veeblefetzer, is this lets me include reflections in the Veeblefetzer's display.
      Now to the challenges I'm ill-equipped to figure out.  
      The function I use to display the Veeblefetzer is below. It, too, is drawn from some of examples by @UEZ.
      There are actually two functions below, one I use to display the PNG graphic, and one that can be used to fade the graphic in or out.  I include it here only because it might be applicable to my ancillary goal of needing to clear the text on the handheld display before streaming the next message onto the Veeblefetzer's display.  I realize that the fade in/out function is for graphic objects, so it may not be applicable to text. 
       
      ; Display the image at center unless otherwise specified. If Fader will not be used then $iAlpha's default of 0xFF is good. ; If Fader will be used then start with $iAlpha equal to zero. Option to make this image "Always on top" is also available. Func DisplayImage($sFile, $iPosX = -1, $iPosY = -1, $iAlpha = 0xFF, $bTopmost = True) Local Const $hBmp_Background = _GDIPlus_BitmapCreateFromFile($sFile) ;load the image If @error Then Return SetError(1, 0, 0) ;image cannot be loaded Local Const $iW = _GDIPlus_ImageGetWidth($hBmp_Background), $iH = _GDIPlus_ImageGetHeight($hBmp_Background) ;get the dimension of the background image Local Const $hGUI = GUICreate("", $iW, $iH, $iPosX, $iPosY, $WS_POPUP, BitOR($WS_EX_LAYERED, $WS_EX_TOPMOST * $bTopmost, $WS_EX_TOOLWINDOW)) ;create GUI with appropriate styles and extented style (borderless transparent GUI) GUICtrlCreateLabel("", 0, 0, $iW, $iH, Default, $GUI_WS_EX_PARENTDRAG) ;create a hidden label for GUI dragging GUISetState(@SW_SHOW, $hGUI) ;show GUI Local Const $hBitmap = _GDIPlus_BitmapCreateFromScan0($iW, $iH) ;define an empty bitmap where all the gfx stuff will copied to Local Const $hGfx = _GDIPlus_ImageGetGraphicsContext($hBitmap) ;get the context to the bitmap to be able to copy / draw to the bitmap _GDIPlus_GraphicsDrawImageRect($hGfx, $hBmp_Background, 0, 0, $iW, $iH) ;draw background image to the empty bitmap ;display GDI+ with transparency on desktop Local Const $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;convert GDI+ image to GDI to display it on the screen using GDI functions Local Const $hScrDC = _WinAPI_GetDC($hGUI) ;get the device context (dc) handle of the GUI Local Const $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC) ;create a compatible dc handle Local Const $hOld = _WinAPI_SelectObject($hMemDC, $hHBitmap) ;selects the GDI bitmap object into the specified device context Local Const $tSize = DllStructCreate($tagSIZE) ;create a $tagSIZE struct (x = width, y = height) DllStructSetData($tSize, "X", $iW) ;set data for width DllStructSetData($tSize, "Y", $iH) ;set data for height Local $tSource = DllStructCreate($tagPOINT) ;create a $tagPOINT struct (x = x position, y = y position) Local $tBlend = DllStructCreate($tagBLENDFUNCTION) ;create $tagBLENDFUNCTION struct -> see help file for more info DllStructSetData($tBlend, "Alpha", $iAlpha) ;set the alpha channel of the GUI -> 255 = opaque, 0 = transparent DllStructSetData($tBlend, "Format", 1) ;set the format to 1 -> bitmap has alpha channels DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $hGUI, "handle", $hScrDC, "ptr", 0, "struct*", $tSize, "handle", $hMemDC, "struct*", $tSource, "dword", 0, "struct*", $tBlend, "dword", $ULW_ALPHA) ;display bitmap on screen ;release resources otherwise memory will filled up (memory leak) _GDIPlus_GraphicsDispose($hGfx) _GDIPlus_BitmapDispose($hBitmap) Local $aResource[7] = [$hGUI, _ ;GUI handle $hScrDC, _ ;device context (dc) handle of the GUI (GDI) $hHBitmap, _ ;GDI bitmap handle of the displayed image $hMemDC, _ ;compatible dc handle from $hScrDC $tBlend, _ ;tBlend struct (source blend oper., flags, alpha value, format) -> see help file for description $tSize, _ ;tSize struct (width and height of the window / image) $tSource] ;tSource struct for x / y position of the GUI Return $aResource ;returns the handles to release it later or to use it for fading effects EndFunc ;==>DisplayImage ; This function releases the resources of a specific image and closes it Func ReleaseResources(ByRef $aResource) If Not IsArray($aResource) Then Return SetError(1, 0, 0) If UBound($aResource) <> 7 Then Return SetError(2, 0, 0) _WinAPI_ReleaseDC($aResource[0], $aResource[1]) _WinAPI_DeleteDC($aResource[3]) _WinAPI_DeleteObject($aResource[2]) GUIDelete($aResource[0]) EndFunc ;==>ReleaseResources ; To fade in an image leave $bIn at default (True); to fade out specify False. ; There are also options to set the ending transparency level (0 transparent, 255 opaque), speed and delay. ; If you change the speed or delay be sure to specify $bIn and $iTrans, otherwise you'll wonder why the fade-in or out isn't what you hoped for. ; The default values are specified in the function below. Func _Fader($res1, $bIn = True, $iTrans = 255, $speed = 3, $delay = 10 ) If Not IsArray($res1) Then Return SetError(1, 0, 0) If UBound($res1) <> 7 Then Return SetError(2, 0, 0) Switch $bIn Case True For $a = 0 To $iTrans Step $speed DllStructSetData($res1[4], "Alpha", $a) DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen Sleep($delay) Next Case Else For $a = $iTrans To 0 Step -$speed DllStructSetData($res1[4], "Alpha", $a) DllCall("user32.dll", "bool", "UpdateLayeredWindow", "hwnd", $res1[0], "handle", $res1[1], "ptr", 0, "struct*", $res1[5], "handle", $res1[3], "struct*", $res1[6], "dword", 0, "struct*", $res1[4], "dword", $ULW_ALPHA) ;display bitmap on screen Sleep($delay) Next EndSwitch EndFunc ;==>_FadeIn  
      Is anyone willing to step in and show me how to use the text display function along with the PNG display function, so that the resulting Veeblefetzer will be a single draggable object on screen?
      I'm equally baffled about how to properly clear off one message before displaying the next.
      The reason?   I have only the most rudimentary grasp of the commands within -- or the relationships between -- what seem like three distinct sections common to each of UEZ's scripts:
      Initialization (which defines a number of attributes, some of which are obvious to me, for text in this case)
      _GDIPlus_Startup() Global $hBrush = _GDIPlus_BrushCreateSolid(0xFF99ff33) Global $hFormat = _GDIPlus_StringFormatCreate() Global $hFamily = _GDIPlus_FontFamilyCreate("VT323") Global $hFont = _GDIPlus_FontCreate($hFamily, 14, 0) Global $tLayout = _GDIPlus_RectFCreate(20, 20, 0, 0) Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) Global $hBitmap = _GDIPlus_BitmapCreateFromScan0(420, 300) Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetTextRenderingHint($hBuffer, 4) _GDIPlus_GraphicsSetSmoothingMode($hBuffer, 4)  
      Delivery... (apparently what's needed to display the text)
      $aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $sMessage, $hFont, $tLayout, $hFormat) _GDIPlus_GraphicsClear($hBuffer, 0x000000) _GDIPlus_GraphicsDrawStringEx($hBuffer, $sMessage, $hFont, $aInfo[0], $hFormat, $hBrush) $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) _WinAPI_BitmapDisplayTransparentInGUI($hHBitmap, $hGUI) _WinAPI_DeleteObject($hHBitmap) Even at my primitive level of understanding I have figured out that you can reuse the above "delivery" section to display other strings before proceeding to the next section.
       
      Cleanup... (apparently needed to release resources, which to me is like closing a previously opened file: it's part of the process so I'll do it):
      _GDIPlus_FontDispose($hFont) _GDIPlus_FontFamilyDispose($hFamily) _GDIPlus_StringFormatDispose($hFormat) _GDIPlus_BrushDispose($hBrush) _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_ImageDispose($hBitmap) _GDIPlus_Shutdown()  
      (You're getting an inside look at a monkey brain at work here!)
      UEZ's script to display the PNG graphic follows a similar pattern. What I cannot figure out is how to merge the two scripts, while avoiding redundancy and conflicts. To clear the text between messages must I release any resources, and if so: which ones? AND, how do I group the PNG graphic with the text so the resulting "object" can be moved around on the screen?
       
       
    • RyukShini
      Image quality is bad compared to paint
      By RyukShini
      #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Icon=car.ico #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GDIPlus.au3> #include <File.au3> #include <Array.au3> #include <ColorConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ProgressConstants.au3> ; Declare array Dim $Images[1] ; Gets all JPG files in the current directory (@ScriptDir). Local $search = FileFindFirstFile("*.jpg") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No JPG files could be found.") Exit EndIf ; Resize array While 1 If IsArray($Images) Then Local $Bound = UBound($Images) ReDim $Images[$Bound+1] EndIf $Images[$Bound] = FileFindNextFile($search) If @error Then ExitLoop WEnd ; Close the search handle FileClose($search) ; Create directory "resized" if not there yet $nymappe = InputBox("Mappe / Bil Navn", "Mappe / Bil Navn") If NOT FileExists(@ScriptDir & "\" & $nymappe & "\") Then DirCreate(@ScriptDir & "\" & $nymappe & "\") EndIf ; Loop for JPGs - gets dimension of JPG and calls resize function to resize to 50% width and 50% height For $i = 1 to Ubound($Images)-1 If $Images[$i] <> "" AND FileExists(@ScriptDir & "\" & $Images[$i]) Then Local $ImagePath = @ScriptDir & "\" & $Images[$i] _GDIPlus_Startup() Local $hImage = _GDIPlus_ImageLoadFromFile($ImagePath) Local $ImageWidth = _GDIPlus_ImageGetWidth($hImage) Local $ImageHeight = _GDIPlus_ImageGetHeight($hImage) _GDIPlus_ImageDispose($hImage) _GDIPlus_Shutdown() ;MsgBox(0,"DEBUG", $ImageWidth & " x " & $ImageHeight) Local $NewImageWidth = ($ImageWidth / 100) * 15 Local $NewImageHeight = ($ImageHeight / 100) * 15 ;MsgBox(0,"DEBUG: " & $i,$Images[$i]) _ImageResize(@ScriptDir & "\" & $Images[$i], @ScriptDir & "\" & $nymappe & "\" & $Images[$i], $NewImageWidth, $NewImageHeight) EndIf Next ; Resize function Func _ImageResize($sInImage, $sOutImage, $iW, $iH) Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0 ;OutFile path, to use later on. Local $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1)) ;OutFile name, to use later on. Local $sOF = StringMid($sOutImage, StringInStr($sOutImage, "\", 0, -1) + 1) ;OutFile extension , to use for the encoder later on. Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1)) ; Win api to create blank bitmap at the width and height to put your resized image on. $hWnd = _WinAPI_GetDesktopWindow() $hDC = _WinAPI_GetDC($hWnd) $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH) _WinAPI_ReleaseDC($hWnd, $hDC) ;Start GDIPlus _GDIPlus_Startup() ;Get the handle of blank bitmap you created above as an image $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP) ;Load the image you want to resize. $hImage2 = _GDIPlus_ImageLoadFromFile($sInImage) ;Get the graphic context of the blank bitmap $hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1) ;Draw the loaded image onto the blank bitmap at the size you want _GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iW, $iH) ;Get the encoder of to save the resized image in the format you want. $CLSID = _GDIPlus_EncodersGetCLSID($Ext) ;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image. Do $i += 1 Until (Not FileExists($sOP & $i & "_" & $sOF)) ;Prefix the number to the begining of the output filename $sOutImage = $sOP & $i & "_" & $sOF ;Save the new resized image. _GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID) ;Clean up and shutdown GDIPlus. _GDIPlus_ImageDispose($hImage1) _GDIPlus_ImageDispose($hImage2) _GDIPlus_GraphicsDispose ($hGraphic) _WinAPI_DeleteObject($hBMP) _GDIPlus_Shutdown() EndFunc Quality gets quite bad compared to using Paint / Photoshop when resizing with GDIPlus
      Any idea how to make the quality better?
      Thanks in advance