Sign in to follow this  
Followers 0
lee321987

_GDIPlus_GraphicsDrawImage

6 posts in this topic

Sometimes when I run this script the image (bitmap.gif) displays, and sometimes it does not. I can't figure out why.

(bitmap.gif is attached)

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>

Global $hForm1, $hBitmap, $hGraphic, $nMsg

$hForm1 = GUICreate("GDI_Tester", 200, 100)
GUISetState(@SW_SHOW, $hForm1)

_GDIPlus_Startup()

$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\bitmap.gif"); create a bitmap object from file
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hForm1); create a graphic object in form1
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0); draws the bitmap image in the graphic


While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then
;~ ; Clean up resources
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_ImageDispose($hBitmap)
        _WinAPI_DeleteObject($hBitmap)
;~ ; Shut down GDI+ library
        _GDIPlus_Shutdown()
        Exit
    EndIf
WEnd

post-49471-12604089610715_thumb.gif

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

You need to redraw the image.

#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>

Global $hForm1, $hBitmap, $hGraphic, $nMsg

$hForm1 = GUICreate("GDI_Tester", 200, 100)
GUIRegisterMsg($WM_PAINT, 'WM_PAINT')
GUISetState(@SW_SHOW, $hForm1)

_GDIPlus_Startup()

$hBitmap = _GDIPlus_BitmapCreateFromFile(@ScriptDir & "\bitmap.gif"); create a bitmap object from file
$hGraphic = _GDIPlus_GraphicsCreateFromHWND($hForm1); create a graphic object in form1
_GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0); draws the bitmap image in the graphic


While 1
    $nMsg = GUIGetMsg()
    If $nMsg = $GUI_EVENT_CLOSE Then
;~ ; Clean up resources
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_ImageDispose($hBitmap)
        _WinAPI_DeleteObject($hBitmap)
;~ ; Shut down GDI+ library
        _GDIPlus_Shutdown()
        Exit
    EndIf
WEnd

Func WM_PAINT($hWnd, $iMsg, $wParam, $lParam)
    _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT
Edited by Yashied

Share this post


Link to post
Share on other sites

Sometimes when? I can think of two possibilities.

1) You set the focus to another window (which covers your GUI) and then switch back to your GUI, you see it.

2) You minimize your GUI and restore the window, you don't see it.

Do you mean that on start up, you sometimes see it and other times you don't?

Share this post


Link to post
Share on other sites

Yes, on statup, sometimes the image is visible, sometimes not.

To address your points:

1) That makes it visible.

2) Minimize/restore does not make it visible.

@Yashied

Thank you, but still has intermittent no-display of the image.

Share this post


Link to post
Share on other sites

And what happen if you add a sleep of 500 ms just after you show the window but before you draw the image?

Share this post


Link to post
Share on other sites

Thank you. I put a Sleep(20) right before _GDIPlus_GraphicsDrawImage, and the image now always shows.

Thanks a lot.

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