Sign in to follow this  
Followers 0

Z-index image overlay, how to with Autoit? [SOLVED]

4 posts in this topic

#1 ·  Posted (edited)

Hi.. In html 5 4example I use Z-index on div object to overlay the images, how could I do this for example with the object pic and another object in the gui?

How can I use the transparency of a PNG file?

someone has already tried?


Edited by rootx

Share this post

Link to post
Share on other sites

The Z-Order is in the order of creating. When PNG-File has transparency it is used.  I use GUICtrlPic.au3 for creating Controls with PNG-image.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUICtrlPic.au3>

Global $aHoverBtn[5][5]
$aHoverBtn[0][1] = @ScriptDir & "\Pictures\Up.png"
$aHoverBtn[0][2] = @ScriptDir & "\Pictures\UpHovered.png"
$aHoverBtn[0][3] = @ScriptDir & "\Pictures\UpPressed.png"
$aHoverBtn[0][4] = False

$aHoverBtn[1][1] = @ScriptDir & "\Pictures\Down.png"
$aHoverBtn[1][2] = @ScriptDir & "\Pictures\DownHovered.png"
$aHoverBtn[1][3] = @ScriptDir & "\Pictures\DownPressed.png"
$aHoverBtn[1][4] = False

$aHoverBtn[2][1] = @ScriptDir & "\Pictures\Left.png"
$aHoverBtn[2][2] = @ScriptDir & "\Pictures\LeftHovered.png"
$aHoverBtn[2][3] = @ScriptDir & "\Pictures\LeftPressed.png"
$aHoverBtn[2][4] = False

$aHoverBtn[3][1] = @ScriptDir & "\Pictures\Right.png"
$aHoverBtn[3][2] = @ScriptDir & "\Pictures\RightHovered.png"
$aHoverBtn[3][3] = @ScriptDir & "\Pictures\RightPressed.png"
$aHoverBtn[3][4] = False

$aHoverBtn[4][1] = @ScriptDir & "\Pictures\Exit.png"
$aHoverBtn[4][2] = @ScriptDir & "\Pictures\ExitHovered.png"
$aHoverBtn[4][3] = @ScriptDir & "\Pictures\ExitPressed.png"
$aHoverBtn[4][4] = False

Global $hGui = GUICreate("Hovered Ping-Buttons", 612, 369, 271, 235)
Local $sAutoItPath = StringReplace(@AutoItExe, "autoit3.exe", "")
ConsoleWrite($sAutoItPath & "Examples\GUI\msoobe.jpg" & @CRLF)
Local $Background = _GUICtrlPic_Create($sAutoItPath & "Examples\GUI\msoobe.jpg", 0, 0, 612, 369, $SS_CENTERIMAGE, Default)
GUICtrlSetState(-1, $Gui_DISABLE)
Local $idTorus = _GUICtrlPic_Create($sAutoItPath & "Examples\GUI\Torus.png", 8, 8, 68, 71, $SS_CENTERIMAGE, Default)
GUICtrlSetState(-1, $Gui_DISABLE)

$aHoverBtn[0][0] = _GUICtrlPic_Create($aHoverBtn[0][1], 460, 8, 48, 48, BitOR($SS_CENTERIMAGE, $SS_NOTIFY), Default) ;Up
$aHoverBtn[1][0] = _GUICtrlPic_Create($aHoverBtn[1][1], 460, 138, 48, 48, BitOR($SS_CENTERIMAGE, $SS_NOTIFY), Default) ;Down
$aHoverBtn[2][0] = _GUICtrlPic_Create($aHoverBtn[2][1], 400, 73, 48, 48, BitOR($SS_CENTERIMAGE, $SS_NOTIFY), Default) ;Left
$aHoverBtn[3][0] = _GUICtrlPic_Create($aHoverBtn[3][1], 520, 73, 48, 48, BitOR($SS_CENTERIMAGE, $SS_NOTIFY), Default) ;Right
$aHoverBtn[4][0] = _GUICtrlPic_Create($aHoverBtn[4][1], 540, 266, 48, 48, BitOR($SS_CENTERIMAGE, $SS_NOTIFY), Default) ;Exit

While 1
    #Region ;Hover Or Not?
    $Info = GUIGetCursorInfo($hGui)
    For $i = 0 To UBound($aHoverBtn) - 1
        If $Info[4] = $aHoverBtn[$i][0] Then
            If $aHoverBtn[$i][4] Then _GUICtrlPic_SetImage($aHoverBtn[$i][0], $aHoverBtn[$i][2], True)
            $aHoverBtn[$i][4] = False
            If Not $aHoverBtn[$i][4] Then _GUICtrlPic_SetImage($aHoverBtn[$i][0], $aHoverBtn[$i][1], True)
            $aHoverBtn[$i][4] = True
    #EndRegion ;Hover Or Not?
    $nMsg = GUIGetMsg()
    $aPos = ControlGetPos($hGui, "", $idTorus)
    Switch $nMsg
        Case $Gui_EVENT_CLOSE
        Case $aHoverBtn[0][0]
            If _GuiCtrlPic_AnimButton($hGui, $aHoverBtn[0][0], $aHoverBtn[0][1], $aHoverBtn[0][3]) Then $aPos[1] -= 5 ;nach oben
        Case $aHoverBtn[1][0]
            If _GuiCtrlPic_AnimButton($hGui, $aHoverBtn[1][0], $aHoverBtn[1][1], $aHoverBtn[1][3]) Then $aPos[1] += 5 ;nach unten
        Case $aHoverBtn[2][0]
            If _GuiCtrlPic_AnimButton($hGui, $aHoverBtn[2][0], $aHoverBtn[2][1], $aHoverBtn[2][3]) Then $aPos[0] -= 5 ;nach links
        Case $aHoverBtn[3][0]
            If _GuiCtrlPic_AnimButton($hGui, $aHoverBtn[3][0], $aHoverBtn[3][1], $aHoverBtn[3][3]) Then $aPos[0] += 5 ;nach rechts
        Case $aHoverBtn[4][0]
            If _GuiCtrlPic_AnimButton($hGui, $aHoverBtn[4][0], $aHoverBtn[4][1], $aHoverBtn[4][3]) Then Exit
    ControlMove($hGui, "", $idTorus, $aPos[0], $aPos[1])


What have you tried?

1 person likes this

Share this post

Link to post
Share on other sites
#include <GDIPlus.au3>
#include <GUIConstants.au3>
#include <WinAPI.au3>

Global $hMain = GUICreate("Example", 1024, 768)
Global $picImage = GUICtrlCreatePic("", 0, 0, 1024, 768)
Global $hHBitmapImages = CreateImage()

_WinAPI_DeleteObject(GUICtrlSendMsg($picImage, $STM_SETIMAGE, $IMAGE_BITMAP, $hHBitmapImages))

GUISetState(@SW_SHOW, $hMain)

While (True)
    Switch (GUIGetMsg())
        Case $GUI_EVENT_CLOSE


Func CreateImage()
    Local $hBitmap = _GDIPlus_BitmapCreateFromScan0(1024, 768)
    Local $hGraphics = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    Local $sRegPath = "HKLM\SOFTWARE\Wow6432Node\AutoIt v3\AutoIt"
    Local $sAutoitPath = RegRead($sRegPath, "InstallDir")
    Local $hImageMsoobe = _GDIPlus_ImageLoadFromFile($sAutoitPath & "\Examples\GUI\msoobe.jpg")
    Local $hImageMsLogo = _GDIPlus_ImageLoadFromFile($sAutoitPath & "\Examples\GUI\mslogo.jpg")
    Local $hImageTorus = _GDIPlus_ImageLoadFromFile($sAutoitPath & "\Examples\GUI\torus.png")
    Local $hHReturn = Null


    _GDIPlus_GraphicsDrawImage($hGraphics, $hImageMsoobe, 0, 0)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImageMsLogo, 0, 768 - _GDIPlus_ImageGetHeight($hImageMsLogo))
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImageTorus, (1024 / 2) - (_GDIPlus_ImageGetWidth($hImageTorus) / 2), 0)

    $hHReturn = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)

    Return $hHReturn
EndFunc   ;==>DrawImages


1 person likes this

Share this post

Link to post
Share on other sites


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

    • SimTheNo1
      By SimTheNo1
      I am busy with building a solution for change monitoring of VOIP call program and to be properly automated means among others need for some limited OCR functionality. Current works of others are way too much overkill for this case what makes the need to build it myself. But to do it properly I significantly have to increase my knowledge about digital graphics management.
      For now I already have discovered here and there some mind blowing  Autoit miracles what can be achieved with Windows own possibilities to manipulate that what is output to the monitor. And as far I can judge there are 2 options to process graphics without use of any external libraries like ImageMagick, FreeImage and so on. These are:
       WinAPI  GDIPlus It is for me quite obvious to have various holes in general understanding of graphics and it is once more very clear what advantages gives consistent general study in 1 or another official institutions like University.  Cause there you are introduced into certain domain of knowledge in a way which usually has been perfected over long period of time. So you are not overloaded by stuff which requires a certain amount of information to be initially clear for you. For example, before starting to solve physics you first learn to read, count and so on and then move to subjects like physics.
      Though in my case opportunity to study in such educational system I had only for 8 years, from my 7th to 15th year of age in the country that was falling apart now Ukraine but used to be USSR, was all what it was. After have immigrated to Netherlands possibilities to study further haven't occur. And this therefor causes often various implications when going deep in that or another field of practical knowledge acquiring for any needed physical result, like programming to perform enormous amount of tasks. In this particular case automating VOIP call program.
      Anyway, right now I think the best direction to move is to concentrate on as basic as possible image management and if someone would maybe explain in general what is a pixel will definitely help. Particularly I am very curious about how to do picture manipulations in Autoit. Especially would help a lot to produce eventually following functions:
      createImage($imageFileName, $width, $height, $color) readImagePixel($imageFileName, $x, $y)  writeImagePixel($imageFileName, $x, $y) I do not know exactly how image is handled in computer but preferably above mentioned functions should deal with so far possible origin of graphics creation on computer. But nevertheless I definitely would love to hear any proposition for solution.
      The problem with explaining screenshots:
       VOIPConnect full Window  Part of Window with control to monitor for changes  Exact location of area where actual changes occur and have to be processed  It comes down to a rectangle of approximately 51 pixel wide and 7 pixel high. In fact if I get to learn as far as to be able exactly read, write and compare 2 images consistently across different computers I could narrow down then even further the area to watch as little as a square of 2-5 pixels wide. 
      To finish here is last detail about particularly no need for ultra fast solution at all. This because it is needed only once when it is first run on a new computer and to have to wait few minutes while it is being set instead of just a few seconds make no sence.
      This is it and what I too think to do beside this very particular case is to purify out beautiful generic Autoit functions for core image manipulation by using WinAPI or/and GDIPlus. 
    • Ian_Mac
      By Ian_Mac
      Func dg_get_images() $x1=0 $y1=0 ;MsgBox(0,"start","start") do $result = _ImageSearch("C:\Users\Server\Desktop\my project\image.png",1,$x1,$y1,0) until $result = 1; if $result=1 Then MouseMove($x1,$y1,3) MouseClick("left", $x1,$y1, 1) WinWait("[Title:TightVNC File Transfer]", "", 10) EndIf  this code works when i search the image, but when i change the location of the desktop icon it can't find the desktop icon anymore.   i wanna try image search area. but i don't know how to use it because i cant understand the parameter for the image search area.  please help me how to solve it thank you in advance.
    • rootx
      By rootx
      I would like to download the first 5 images in a folder. THX.
      #include <INet.au3> #include <String.au3> #include <Array.au3> Global $sSource, $aImgURL, $sKeyWord $sKeyWord = "pug" $sSource = _INetGetSource("" & $sKeyWord & "&tbm=isch") $aImgURL = _StringBetween($sSource, 'src="', '"') For $x = 1 to UBound($aImgURL)-1 ConsoleWrite($aImgURL[$x]&@CRLF) Next  
    • nbg15
      By nbg15
      Hello everybody..
      i have this picture here *attached* and this script here: 
      $ImageToReadPath = @MyDocumentsDir & "\GDIPlus_Image2.jpg" $ResultTextPath = @MyDocumentsDir & "\Result" $OutPutPath = $ResultTextPath & ".txt" $TesseractExePath = @MyDocumentsDir & "\Tesseract.exe" ShellExecuteWait($TesseractExePath, '"' & $ImageToReadPath & '" "' & $ResultTextPath & '"', "", "", @SW_HIDE) If @error Then Exit MsgBox(0, "Error", @error) EndIf MsgBox(0, "Result", FileRead($OutPutPath)) FileDelete($OutPutPath)  
      but tesseract doesnt recognized the correct word... and gives me trash back...

      this is the image >> 
      and the result was >> "samm" 

      the image was an normal jpg and generated with this code here:
      _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image2.jpg", 712,268,853,284)
      Could anybody give me a hint what i can do better to get this easy image to text?
      thank u very much!!!
      Edit: i also tried to capture the screen as bmp with a higher resolution... nothing changed... 
      _ScreenCapture_SetBMPFormat(4) _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image.bmp", 712,279,853,295)  
    • RyukShini
      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