Jump to content

Move or delete a image on GDI+


Recommended Posts

Sorry, i'm brazilian and my english is bad.

i want make a img move on Gui, but i need delete a imagem and create a new, when i use " _GDIPlus_GraphicsClear($hGraphic, 0xFF000000)" for delete a imagem and recreate other, this cleanner all image on GUI. Look the code...

 

#include <GUIConstants.au3>
#include <File.au3>
#include <GDIPlus.au3>
 
 
$brgui=GUICreate("Test Frontend", 800, 600, -1, -1, BitOR ($WS_POPUP,$WS_BORDER))
 
;Imagem de fundo
GUICtrlCreatePic("C:\ARCADE\Layouts\skin.jpg",0,0, 800,600)
GUICtrlSetState (-1, $GUI_DISABLE)
 
GUISetState  ()
 
;inicia GDI+
 
_GDIPlus_StartUp()
local $imagem=_GDIPlus_ImageLoadFromFile("C:\ARCADE\Layouts\select.png")
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($brgui)
_WinAPI_RedrawWindow($brgui, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW, $RDW_FRAME));
_GDIPlus_GraphicsDrawImageRect($hGraphic,$imagem,35,50,309,49)
 
sleep (8000)
_GDIPlus_GraphicsClear($hGraphic, 0xFF000000) ;<--- This delete all image on gui... :<
_GDIPlus_GraphicsDrawImageRect($hGraphic,$imagem,35,150,309,49)
 
while 1
sleep(100)
wend

 

Edited by PedroWarlock
Link to comment
Share on other sites

Here is a older script of mine using a UDF from @Großvater (in english = grandpa):

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_UseX64=y
#AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GUICtrlPic.au3>
#include <Array.au3>

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

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

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

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

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

Global $nMsg, $aPos, $aInfo
Global $hGui = GUICreate("Hovered Ping-Buttons", 612, 369, 271, 235)
Global $sAutoItPath
If @Compiled Then
    $sAutoItPath=RegRead64('HKLM\Software\AutoIt v3\AutoIt', 'InstallDir')&'\'
Else
    $sAutoItPath= StringReplace(StringReplace(@AutoItExe, "_x64", ""), "autoit3.exe", "")&'\'
EndIf

Global $Background = _GUICtrlPic_Create($sAutoItPath & "Examples\GUI\msoobe.jpg", 0, 0, 612, 369, $SS_CENTERIMAGE, Default)
GUICtrlSetState(-1, $Gui_DISABLE)
Global $idTorus = _GUICtrlPic_Create($sAutoItPath & "Examples\GUI\Torus.png", 88, 8, 68, 71, $SS_CENTERIMAGE, Default)

$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
GUISetState()

While 1
    _GuiCtrlPic_CheckHoverDisabled($hGui, $aHoverBtn)   ;checken ob ein anderes Pic angezeigt werden muß und bei Bedarf anzeigen
    $nMsg = GUIGetMsg()
    $aPos = ControlGetPos($hGui, "", $idTorus)
    Switch $nMsg
        Case $Gui_EVENT_CLOSE
            Exit
        Case $aHoverBtn[0][0]
            If _GuiCtrlPic_AnimButton($hGui, $aHoverBtn[0][0], $aHoverBtn[0][1],$aHoverBtn[0][2], $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][2], $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][2], $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][2], $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][2], $aHoverBtn[4][3]) Then Exit
        Case $GUI_EVENT_PRIMARYDOWN
            ;hier noch DRAGen einfügen
    EndSwitch
    ControlMove($hGui, "", $idTorus, $aPos[0], $aPos[1])
WEnd

Func RegRead64($sKeyname, $sValue)
    ;Aus AutoUpdateIt.au3
    Local $sRes = RegRead($sKeyname, $sValue)
    If @error And @AutoItX64 Then
        $sKeyname = StringReplace($sKeyname, "HKEY_LOCAL_MACHINE", "HKLM")
        $sKeyname = StringReplace($sKeyname, "HKLM\SOFTWARE\", "HKLM\SOFTWARE\Wow6432Node\")
        $sRes = RegRead($sKeyname, $sValue)
        If @error Then
            SetError(1)
            Return ""
        EndIf
    EndIf
    SetError(0)
    Return $sRes
EndFunc   ;==>RegRead64

just test it. You need also:

GUICtrlPic.au3

pictures.zip

Edited by AutoBert
Link to comment
Share on other sites

_GUICtrlPic_Create (used for creating) returns a Control-ID this can used with GUICtrlDelete for deliting the control, for assigning a other image use _GUICtrlPic_SetImage. The GDI-stuff is in the UDF (which i try to extend for loading a image from memory, but this is future).  The extensions of mine that already working are _GuiCtrlPic_CheckHoverDisabled and _GuiCtrlPic_AnimButton (also in the UDF) both are used in script, and both are calling _GUICtrlPic_SetImage for the visual effects. 

Edited by AutoBert
Link to comment
Share on other sites

Look this gif...i put a img in background

$Background=GUICtrlCreatePic("skin.jpg",0,0, 800,600)

and use a image green on GDI+

But when i used...

        _GDIPlus_GraphicsClear($hGraphic, 0xFF000000)                                                           ;<----delete image green
         _GDIPlus_GraphicsDrawImageRect($hGraphic,$imagem,35,$pos_barra,309,49)         :<----Create a new image green in another posicion.

 

 

This "_GDIPlus_GraphicsClear($hGraphic, 0xFF000000) " delete all imagem on GUI... :(   i Need GDI+ for transparency.

 

This function work, but all image on gui blink all the time -->        _WinAPI_InvalidateRect($brgui, 0,true)

 

HnkRErO.gif

Edited by PedroWarlock
Link to comment
Share on other sites

What made you think that _GDIPlus_GraphicsClear($hGraphic, 0xFF000000)  will clear the green color of the graphics? The first parameter of this hex value is the Alpha value, not one of the color values. Green would be the the 5th and 6th numbers in the hex number.

Plus this function doesn't clear a color, it clears TO a color, meaning it will only leave the color selected in the $aRGB value.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Looks like you're gonna need to draw two images, based off your gif you posted. Your menu image and the image you used to show what item is currently selected.

I'm on a new computer with nothing set up and I don't have the time to actually write it out. If you can't figure it out by tomorrow I'll see if I can help out.

Your logic should be draw the background image, draw your selector image. Whenever a new item is selected you want to clear the graphic then draw the background image, then the selector image (in the new coordinates).

Link to comment
Share on other sites

2 hours ago, BrewManNH said:

What made you think that _GDIPlus_GraphicsClear($hGraphic, 0xFF000000)  will clear the green color of the graphics? The first parameter of this hex value is the Alpha value, not one of the color values. Green would be the the 5th and 6th numbers in the hex number.

Plus this function doesn't clear a color, it clears TO a color, meaning it will only leave the color selected in the $aRGB value.

I said green image referring to this picture

v8FfXbv.png

 

2 hours ago, InunoTaishou said:

Looks like you're gonna need to draw two images, based off your gif you posted. Your menu image and the image you used to show what item is currently selected.

I'm on a new computer with nothing set up and I don't have the time to actually write it out. If you can't figure it out by tomorrow I'll see if I can help out.

Your logic should be draw the background image, draw your selector image. Whenever a new item is selected you want to clear the graphic then draw the background image, then the selector image (in the new coordinates).

 

Thanks. I want move this image green, but I think can not move image on GDI + (sorry my english) . I'll wait for you tomorrow :)

 

 

my question is like this topic, but the soluction blurs the gui elements.

 

Look my problem. The image repeat

 

kBu5UEy.gif

Edited by PedroWarlock
Link to comment
Share on other sites

Sorry for the late reply. Here's a rough design, hopefully it helps.

#include <GDIPlus.au3>
#include <ScreenCapture.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

_GDIPlus_Startup()

Global $frmMain = GUICreate("Example", @DesktopWidth, @DesktopHeight)
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($frmMain)
Global $hBitmap = _GDIPlus_BitmapCreateFromGraphics(@DesktopWidth, @DesktopHeight, $hGraphic)
Global $hBuffer = _GDIPlus_ImageGetGraphicsContext($hBitmap)
Global $iCurrentZone = 1

    $hHBitmap = _ScreenCapture_Capture("")
    $hImageBg  = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
    _WinAPI_DeleteObject($hHBitmap)

    $hHBitmap = _ScreenCapture_Capture("", 0, 0, 400, 200)
    $hImageTop = _GDIPlus_BitmapCreateFromHBITMAP($hHBitmap)
    _WinAPI_DeleteObject($hHBitmap)

   GUISetState(@SW_SHOW, $frmMain)

   _GDIPlus_GraphicsDrawImage($hBuffer, $hImageBg, 0, 0)
   _GDIPlus_GraphicsDrawImage($hBuffer, $hImageTop, 400, 200)
   _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)

While(True)
   For $i = 0 to 4
      Local $aMousePos = MouseGetPos()
      ToolTip($iCurrentZone)
      ; Got the mouse position and I'm not checking the current area. This will prevent a lot of redrawing of the graphic
      If (IsArray($aMousePos) and $iCurrentZone <> $i) Then
         ; Checking to make sure that the mouse position is in a new zone
         If (($aMousePos[0] >= 0 and $aMousePos[1] >= $i * 200) and ($aMousePos[1] < ($i + 1) * 200)) Then
            $iCurrentZone = $i
            
            ; Clear the buffer, which is a graphic object
            _GDIPlus_GraphicsClear($hBuffer)
            
            ; Redraw everything with the top image at the new position
            _GDIPlus_GraphicsDrawImage($hBuffer, $hImageBg, 0, 0)
            _GDIPlus_GraphicsDrawImage($hBuffer, $hImageTop, 400, $i * 200)
            _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
         EndIf
      EndIf
   Next
   Sleep(100)
WEnd

 

Link to comment
Share on other sites

On 20/07/2016 at 8:28 PM, InunoTaishou said:

Sorry for the late reply. Here's a rough design, hopefully it helps.

 

 

@InunoTaishou I have to create a new background for the gui ever? :(  If i want create 10 image and have to delete 1 then i have to create again 9 images? (Sorry my english - Google translate-)

Edited by PedroWarlock
Link to comment
Share on other sites

Yes, you have to redraw everything when you change something.

I've also had the idea to clone the area of the image that's going to change, draw the new image over the original area, then when the image changes to draw the cloned bitmap back to the original spot instead of redrawing everything, but it's something I never actually experimented with to see if it was efficient/effective. Just simpler to redraw everything.

Link to comment
Share on other sites

3 hours ago, InunoTaishou said:

Yes, you have to redraw everything when you change something.

I've also had the idea to clone the area of the image that's going to change, draw the new image over the original area, then when the image changes to draw the cloned bitmap back to the original spot instead of redrawing everything, but it's something I never actually experimented with to see if it was efficient/effective. Just simpler to redraw everything.


Exist any UDF that add .png (transparent) in the GUI , but has (GUICtrlSetImage) option or movement (GUICtrlSetPos)?
Edited by PedroWarlock
Link to comment
Share on other sites

11 minutes ago, InunoTaishou said:

Not a standard UDF but you can use GDI+ to load a .png file (transparent) and set it to a picture control. Can't remember if it will retain its transparency when you set it to a picture control though, it's been a while.

 

 

Thanks!! I found a good  UDF , GIF animation.

Link to comment
Share on other sites

9 hours ago, PedroWarlock said:

Exist any UDF that add .png (transparent) in the GUI , but has (GUICtrlSetImage) option or movement (GUICtrlSetPos)?

Yes already posted in

attach some files and i make a demo using your files. Btw.: @Großvater's UDF is based on func's and ideas from UEZ.

@UEZ: would you please so kind, to extend this UDF with func: _GUICtrlPic_LoadImageFromMem, as Großvater's "Letzte Aktivität 27. August 2011" i think he has got a other (hopefully better) job from the CEO of Universe.com. I have not enough time and also to less AutoItskills.  

i have already a placeholder (just a copy from _GUICtrlPic_LoadImage) inserted. 

Link to comment
Share on other sites

@AutoBert: well, Großvater coded the GDI+ stuff hard coded instead of using functions from GDIPlus.au3.

 

Non tested version:

; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlPic_BitmapCreateFromMemory
; Description ...: Bilddatei laden und HBITMAP erzeugen
; Syntax.........: _GUICtrlPic_BitmapCreateFromMemory($binImage)
; Parameters ....: $binImage         - Binär Code eines Bildes
; Return values .: Im Erfolgsfall: Array mit drei Einträgen, Array[0] enthält ein HBITMAP-Handle,
;                                  Array[1] die Breite und Array[2] die Höhe der Bitmap
;                  Im Fehlerfall: False, @error und @extended enthalten ggf. ergänzende fehlerbeschreibende Werte
; Author ........: Großvater (www.autoit.de)
; Modified.......: autoBert (begin of work)
; Remarks .......: Die Funktion kann auch einzeln genutzt werden, um eine Bitmap zu laden und dann per
;                  GUICtrlSendMsg($idPIC, $STM_SETIMAGE, $IMAGE_BITMAP, $hBitmap) einem Pic-Control zuzuweisen.
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================
Func _GUICtrlPic_BitmapCreateFromMemory($binImage)
    Local $aResult, $hBitmap, $hImage, $Height, $Width
    Local $aBitmap[3] = [0, 0, 0]
    Local $__h_GDIPDll = DllOpen("GDIPlus.dll")
    If $__h_GDIPDll = -1 Then Return SetError(1, 2, $aBitmap)
    Local $tInput = DllStructCreate("UINT Version;ptr Callback;BOOL NoThread;BOOL NoCodecs")
    Local $pInput = DllStructGetPtr($tInput)
    Local $tToken = DllStructCreate("ULONG_PTR Data")
    Local $pToken = DllStructGetPtr($tToken)
    DllStructSetData($tInput, "Version", 1)
    $aResult = DllCall($__h_GDIPDll, "INT", "GdiplusStartup", "Ptr", $pToken, "Ptr", $pInput, "Ptr", 0)
    If @error Then Return SetError(@error, @extended, $aBitmap)

    $hImage = _GDIPlus_BitmapCreateFromMemory($binImage)
    If @error Or $aResult[2] = 0 Then
        Local $Error = @error, $Extended = @extended
        DllCall($__h_GDIPDll, "None", "GdiplusShutdown", "Ptr", DllStructGetData($tToken, "Data"))
        DllClose($__h_GDIPDll)
        Return SetError($Error, $Extended, $aBitmap)
    EndIf
    
    $aResult = DllCall($__h_GDIPDll, "INT", "GdipGetImageWidth", "Handle", $hImage, "UINT*", 0)
    $Width = $aResult[2]
    $aResult = DllCall($__h_GDIPDll, "INT", "GdipGetImageHeight", "Handle", $hImage, "UINT*", 0)
    $Height = $aResult[2]
    $aResult = DllCall($__h_GDIPDll, "INT", "GdipCreateHBITMAPFromBitmap", "Handle", $hImage, "Ptr*", 0, "DWORD", 0xFF000000)
    $hBitmap = $aResult[2]
    DllCall($__h_GDIPDll, "INT", "GdipDisposeImage", "Handle", $hImage)
    DllCall($__h_GDIPDll, "None", "GdiplusShutdown", "Ptr", DllStructGetData($tToken, "Data"))
    DllClose($__h_GDIPDll)
    $aBitmap[0] = $hBitmap
    $aBitmap[1] = $Width
    $aBitmap[2] = $Height
    Return $aBitmap
EndFunc   ;==>_GUICtrlPic_LoadImage

 

To make the UDF more maintainable I would suggest to convert the hard coded lines to functions used in GDIPlus.au3.

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...