Jump to content
Sign in to follow this  

GUICtrlPic - display resized image

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 $graphicview = GUICtrlCreatePic("", 50,5, 200,150, $SS_SUNKEN)


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

; Insert picture



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))

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)



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

Share this post

Link to post
Share on other sites

Well, yeah. I've seen that before and made a futile attempt to reconstruct what you are doing there. Copying would have served me better.

Thanks, problem solved :)

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...