Jump to content
Sign in to follow this  
Dolemite50

GDI help needed

Recommended Posts

Dolemite50

Hi,

If I show an image using:

$hPicHnd = _GDIPlus_ImageLoadFromFile($sPicPath)

and display it using:

_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hPicHnd, 0, 0, ...

How do I delete that image?

I've tried:

_GDIPlus_ImageDispose($hPicHnd)
 _GDIPlus_GraphicsDispose($hPicHnd)
GUIDelete($hPicHnd)
GuiCtrlDelete($hPicHnd)

...etc. No luck.

Any help? Thanks!

Share this post


Link to post
Share on other sites
SmOke_N

Hi,

If I show an image using:

$hPicHnd = _GDIPlus_ImageLoadFromFile($sPicPath)

and display it using:

_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hPicHnd, 0, 0, ...

How do I delete that image?

I've tried:

_GDIPlus_ImageDispose($hPicHnd)
 _GDIPlus_GraphicsDispose($hPicHnd)
GUIDelete($hPicHnd)
GuiCtrlDelete($hPicHnd)

...etc. No luck.

Any help? Thanks!

What does:
#include <WinAPI.au3>
_WinAPI_DeleteObject($hPicHnd)
Do for you?

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
Dolemite50

Howdy Smoke N!

Long time no see and thanks for the response.

Still no luck on the suggestion. I tried the following:

$hPicHnd = _GDIPlus_ImageLoadFromFile("D:\Autoit\Basic_Demo\imgs\test.gif")
Local $iWidth = _GDIPlus_ImageGetWidth($hPicHnd)
Local $iHeight = _GDIPlus_ImageGetHeight($hPicHnd)
$bPicOK = _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hPicHnd, 0, 0, $iWidth, _
            $iHeight, $iLeft, $iTop, $iWidth, $iHeight)
Sleep(1000)         
_WinAPI_DeleteObject($hPicHnd)

And the image remains.

I'm a little confused because most of the examples I found on the board use something like:

$hPic = _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hPicHnd, ..

..but from what I can gather the return is only a boolean for success. I've been using this method for rollovers and now it looks like I'm probably just stacking images to the ceiling since that last call isn't replacing anything. Which brings up another question, is there a way to get a list of all the objects you've created?

Thanks again, Smoke N!

Share this post


Link to post
Share on other sites
morongo

And the image remains.

I'm a little confused because most of the examples I found on the board use something like:

$hPic = _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hPicHnd, ..

..but from what I can gather the return is only a boolean for success. I've been using this method for rollovers and now it looks like I'm probably just stacking images to the ceiling since that last call isn't replacing anything.

I know nothing about Autoit, haven't even tried it yet but Autoit scripts, ultimately, make straight win32 calls and the way win32 works for bitmaps is you load a bitmap, create a compatible memory bitmap, select your loaded image into the memory context, then invalidate the portion of the window you're showing it in to realize the image.

Even if you subsequently delete the bitmap object (which is in RAM memory), you may not notice any changes to the image on the screen until you select another image into the 'window' context and invalidate the window (SCREEN memory) it's shown in.

All you're really doing is sending a bitmap-pattern to a specific location of screen memory. As long as nothing else is sent to that screen-memory address, nothing will change on your monitor.

However, you're not 'stacking' bitmap objects so you shouldn't have any memory leaks as long as you delete the objects as you've shown in your last post.

I sincerely hope I'm not overstepping anything in the forum by posting this before even running Autoit, however, this is how things work in the 'Windows' world.

Share this post


Link to post
Share on other sites
SmOke_N

I know nothing about Autoit, haven't even tried it yet but Autoit scripts, ultimately, make straight win32 calls and the way win32 works for bitmaps is you load a bitmap, create a compatible memory bitmap, select your loaded image into the memory context, then invalidate the portion of the window you're showing it in to realize the image.

Even if you subsequently delete the bitmap object (which is in RAM memory), you may not notice any changes to the image on the screen until you select another image into the 'window' context and invalidate the window (SCREEN memory) it's shown in.

All you're really doing is sending a bitmap-pattern to a specific location of screen memory. As long as nothing else is sent to that screen-memory address, nothing will change on your monitor.

However, you're not 'stacking' bitmap objects so you shouldn't have any memory leaks as long as you delete the objects as you've shown in your last post.

I sincerely hope I'm not overstepping anything in the forum by posting this before even running Autoit, however, this is how things work in the 'Windows' world.

Nope, you made a good point really. Maybe a simple _SendMessage() + $WM_PAINT would do the trick after deleting the objects :) ...

Oh, and welcome to the forums :lmao: .


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites
rover

use handle you created $hGraphic from

_WinAPI_InvalidateRect($hWnd, 0, 1)

Modified help file example for _GDIPlus_GraphicsDrawImageRectRect()

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hGUI, $hImage, $hGraphic

    _ScreenCapture_Capture (@MyDocumentsDir & "\GDIPlus_Image.jpg", 0, 0, 400, 300)

    $hGUI = GUICreate("", 400, 300)
    GUISetState()

; Initialize GDI+ library and load image
    _GDIPlus_Startup ()
    $hImage = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & "\GDIPlus_Image.jpg")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0, 400, 300, 0, 0, 400, 300)

; Release resources
    _GDIPlus_GraphicsDispose ($hGraphic)
    _GDIPlus_ImageDispose ($hImage)
    _GDIPlus_Shutdown ()

; Clean up screen shot file
    FileDelete(@MyDocumentsDir & "\GDIPlus_Image.jpg")

    Sleep(3000)
    _WinAPI_InvalidateRect($hGUI, 0, 1)

; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE


EndFunc  ;==>_Main

I see fascists...

Share this post


Link to post
Share on other sites
Malkey

use handle you created $hGraphic from

_WinAPI_InvalidateRect($hWnd, 0, 1)

Modified help file example for _GDIPlus_GraphicsDrawImageRectRect()

To make the invalidation of the image a bit more interesting, an effect is added.

#include <GuiConstantsEx.au3>
#include <GDIPlus.au3>
#include <ScreenCapture.au3>

Opt('MustDeclareVars', 1)

_Main()

Func _Main()
    Local $hGUI, $hImage, $hGraphic

    _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image.jpg", 0, 0, 400, 300)

    $hGUI = GUICreate("Test", 400, 300)
    GUISetBkColor(0x9090d0, $hGUI)
    GUISetState()

; Initialize GDI+ library and load image
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & "\GDIPlus_Image.jpg")
    $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
    _GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage, 0, 0, 400, 300, 0, 0, 400, 300)

; Release resources
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_Shutdown()

; Clean up screen shot file
    FileDelete(@MyDocumentsDir & "\GDIPlus_Image.jpg")
    Sleep(3000)
    
; Invalidate Horizontal lines
    Local $aPos = WinGetPos("Test")
    For $x = 1 To $aPos[3] / 10 + 1
        For $y = 0 To $aPos[3] Step $aPos[3] / 10
            Local $tRect = RectStruct(0, $y, 400, $y + $x)
            _WinAPI_InvalidateRect($hGUI, $tRect, 1)
        Next
        Sleep(100)
    Next
    
; Loop until user exits
    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE


EndFunc  ;==>_Main

Func RectStruct($iLeft, $iTop, $iRight, $iBottom)
    Local $tRect = DllStructCreate($tagRECT)
    DllStructSetData($tRect, "Left", $iLeft)
    DllStructSetData($tRect, "Top", $iTop)
    DllStructSetData($tRect, "Right", $iRight)
    DllStructSetData($tRect, "Bottom", $iBottom)
    Return $tRect
EndFunc  ;==>RectStruct

Share this post


Link to post
Share on other sites
rover

To make the invalidation of the image a bit more interesting, an effect is added.

nice one Malkey

just needs an animated window blinds rod overlay on the left :)


I see fascists...

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  

×