Jump to content

How to delete drawen image...


 Share

Recommended Posts

hey there, i'm learning GDI+ functions. but i have one problem. If you just run the script and than press arrow keys, new merlin images will drawen but old ones doesn't erasing,

#include <GuiConstantsEx.au3>
#include <Misc.au3>
; #include <Memory.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>
Opt('MustDeclareVars', 1)
Opt("GUIOnEventMode", 1)

_Main()
While 1
    Sleep(100)
    WEnd
Func _Main()
    Global $hGUI, $hBMP, $hBitmap, $hGraphic, $hImage, $iX, $iY, $hClone,$hBitmap1, $hGraphic1,$hBitmap2, $hGraphic2, $merl
HotKeySet("{RIGHT}", "MoveRight" )
HotKeySet("{LEFT}", "MoveLeft" )
HotKeySet("{UP}", "MoveUP" )
HotKeySet("{DOWN}", "MoveDown" )
HotKeySet("{ESC}", "End" )
    ; Create GUI
    $hGUI = GUICreate("GDI+", 700, 400)
    GUISetOnEvent($GUI_EVENT_CLOSE, "End")
    GUISetState()

    ; Initialize GDI+ library
    _GDIPlus_Startup ()
    ; Save bitmap to file
    ; Clean up resources
    _GDIPlus_BitmapDispose ($hClone)
    _GDIPlus_BitmapDispose($hImage)
    _WinAPI_DeleteObject ($hBMP)

    ; Draw bitmap to GUI
    $hBitmap = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\proxy.jpg")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400)


    $hBitmap1 = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\merlin.gif")
    $hGraphic1 = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    Global $merl = _GDIPlus_GraphicsDrawImageRect ($hGraphic1, $hBitmap1, 3,3, 68,71)
    Global $posx = 3
    Global $posy = 3
EndFunc   ;==>_Main

Func MoveRight ()
_WinAPI_DeleteObject($merl)
;_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400)
;$hBitmap1 = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\merlin.gif")
;$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
$posx = $posx + 68
If $posx > 632 Then $posx = $posx - 68
_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx  ,$posy, 68,71)
Sleep(1000)


EndFunc
Func MoveDown ()
    _WinAPI_DeleteObject($merl)   ;This line doesn
    ;_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400)
    ;$hBitmap1 = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\merlin.gif")
    ;$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
    _GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx ,$posy+71, 68,71)
    $posy = $posy +71
    Sleep(1000)
EndFunc
Func MoveLeft ()
_WinAPI_DeleteObject($merl)
;_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400)
;$hBitmap1 = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\merlin.gif")
;$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx-68 ,$posy, 68,71)
$posx = $posx - 68
Sleep(1000)
EndFunc
Func MoveUp ()
_WinAPI_DeleteObject($merl)
;_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400)
;$hBitmap1 = _GDIPlus_BitmapCreateFromFile (@WorkingDir & "\merlin.gif")
;$hGraphic = _GDIPlus_GraphicsCreateFromHWND ($hGUI)
_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx ,$posy-71, 68,71)
$posy = $posy - 71
Sleep(1000)
EndFunc

Func End()
        ; Clean up resources
        _GDIPlus_GraphicsDispose ($hGraphic1)
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_BitmapDispose ($hBitmap)
    _GDIPlus_BitmapDispose ($hBitmap1)
    _GDIPlus_ShutDown ()
    Exit
EndFunc

post-38557-0-26351400-1291543543_thumb.g

post-38557-0-54179500-1291543557_thumb.j

Link to comment
Share on other sites

Why not simply re-draw the background whenever you re-draw Merlin?

_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap, 0,0, 700,400) ;; added
_GDIPlus_GraphicsDrawImageRect ($hGraphic, $hBitmap1, $posx ,$posy-71, 68,71)

Well for two reasons,

1-i feel like they all stacking over and over, i don't know if thats true but feels like if i dont delete the old images the new ones just cover the old ones not deleting it.

2- i think it will take more time than just erasing old merlin.

But as i sad i don't know for sure if i'm right...

Link to comment
Share on other sites

GDI+ draws to the screen, and you can't delete stuff from the screen, you redraw them. Stacking doesn't apply to graphics but to controls and windows.

2- i think it will take more time than just erasing old merlin.

Only redraw the background where Merlin was standing, not everything. Edited by AdmiralAlkex
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...