Sign in to follow this  
Followers 0
Waubot

GDIPLus images blank after moving window

5 posts in this topic

These example files work, but when the window placed under another window, then brought to the front again, the image is blank / white.

http://www.autoitscript.com/autoit3/docs/libfunctions/_GDIPlus_ImageResize.htm

http://www.autoitscript.com/autoit3/docs/libfunctions/_GDIPlus_BitmapCreateFromHBITMAP.htm

Does the window have to be refreshed all the time, or is this some kind of graphical issue on my system?

Share this post


Link to post
Share on other sites



Thanks for the quick response.

This works if the window is minimized and restored, it does not work when another window is over it temporarily.

#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>

Example()

Func Example()
    _GDIPlus_Startup()
    Local Const $iW = @DesktopWidth, $iH = @DesktopHeight

    Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iW, $iH) ;create a GDI bitmap by capturing full screen of the desktop
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI bitmap to GDI+ bitmap
    _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore

    Local $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap, $iW / 4, $iH / 4) ;resize image

    Local $hGUI = GUICreate("GDI+ test", $iW / 4, $iH / 4, -1, -1) ;create a test gui to display the resized image
    GUISetState(@SW_SHOW)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 0, 0) ;display scaled image

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            case $GUI_EVENT_RESTORE                 
                _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 0, 0) ;display scaled image
        EndSwitch
    WEnd

    ;cleanup resources
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap_Scaled)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

I think you're looking for the WM_PAINT event.

#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>

#include <WindowsConstants.au3>

Global $hGraphics, $hBitmap_Scaled ;~ <<<<<<<

Example()

Func Example()
    _GDIPlus_Startup()
    Local Const $iW = @DesktopWidth, $iH = @DesktopHeight

    Local $hHBmp = _ScreenCapture_Capture("", 0, 0, $iW, $iH) ;create a GDI bitmap by capturing full screen of the desktop
    $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI bitmap to GDI+ bitmap
    _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore

    $hBitmap_Scaled = _GDIPlus_ImageResize($hBitmap, $iW / 4, $iH / 4) ;resize image

    Local $hGUI = GUICreate("GDI+ test", $iW / 4, $iH / 4, -1, -1) ;create a test gui to display the resized image

    GUIRegisterMsg($WM_PAINT, "WM_PAINT") ;~ <<<<<<<

    GUISetState(@SW_SHOW)

    $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 0, 0) ;display scaled image

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $GUI_EVENT_RESTORE
                _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 0, 0) ;display scaled image

        EndSwitch
    WEnd

    ;cleanup resources
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_BitmapDispose($hBitmap_Scaled)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
EndFunc   ;==>Example

Func WM_PAINT($hWnd, $iMsgm, $wParam, $lParam) ;~ <<<<<<<
    #forceref $hWnd, $iMsgm, $wParam, $lParam

    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap_Scaled, 0, 0)

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_PAINT
Edited by Tekk

Share this post


Link to post
Share on other sites

That did it, thanks :)

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