Jump to content

GUICtrlPic - display resized image


Armag3ddon
 Share

Recommended Posts

Hi everyone!

I've worked my way through the forum but now I'm stuck. I have found lots of code on how to resize images using GDI+ but obviously I do something wrong.

I want an element that displays an image in 200x150 pixels but my code crashes on two different lines without further notice.

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

; Create GUI
Global $main = GUICreate("testcase", 800, 600, -1, -1, BitOR($WS_CAPTION, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SYSMENU, $WS_THICKFRAME, $DS_CONTEXTHELP, $WS_SYSMENU, $WS_VISIBLE))
Global $graphicview = GUICtrlCreatePic("", 50,5, 200,150, $SS_SUNKEN)

_GDIPlus_Startup()

$png = StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUITorus.png")

; Insert picture

ShowGraphic($png)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func ShowGraphic($file)
    ; load image
    $img = _GDIPlus_ImageLoadFromFile($file)
    $big = _GDIPlus_BitmapCreateHBITMAPFromBitmap($img)
    ; Resize image
    $hWnd = _WinAPI_GetDesktopWindow()
    $hDC = _WinAPI_GetDC($hWnd)
    $hBMP = _WinAPI_CreateCompatibleBitmap($hDC, 200, 150)
    _WinAPI_ReleaseDC($hWnd, $hDC)
    $bmp = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)

    $hGraphics = _GDIPlus_ImageGetGraphicsContext($bmp)
    ;_GDIPlus_GraphicsDrawImageRect($hGraphics, $big, 0,0, 200,150)

    ; show image in gui
    _WinAPI_DeleteObject(GUICtrlSendMsg($graphicview, 0x0172, 0, $bmp))
    _GDIPlus_GraphicsDispose($hGraphics)
    ;_GDIPlus_ImageDispose($big)
    _WinAPI_DeleteObject($hBMP)
EndFunc

So this is my test case. I get crashes when I uncomment the following lines (each line crashes separately):

_GDIPlus_GraphicsDrawImageRect($hGraphics, $big, 0,0, 200,150)

and

_GDIPlus_ImageDispose($big)

I'm not really sure what I do with GDI+, I mainly copied stuff from the forum, so yeah, I'm lost on this :)

Edited by Armag3ddon
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...