Sign in to follow this  
Followers 0
Armag3ddon

GUICtrlPic - display resized image

4 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Argh, copying killed all empty lines and indentation %(

/e

fixed

Edited by Armag3ddon

Share this post


Link to post
Share on other sites

Check this out:

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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  
Followers 0