Sign in to follow this  
Followers 0
jWalker

GDI+ scale images

3 posts in this topic

Is it possible to change the size of images in GDI+ ?

$hImage = _GDIPlus_ImageLoadFromFile($sPath)

This is the function that i use...

if i do this:

_GDIPlus_GraphicsDrawImage($aWindow[2], $hImage, $posX, $posY)

The picture comes to my screen but i see there no possibility to resize / scale the picture!

(I don't want to resize and save the picture with GDI+, i want to draw it bigger on my screen)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try this:

#include <gdiplus.au3>

_GDIPlus_Startup()

Global $fScaleW = 2.5
Global $fScaleH = 2.5
Global $sFile = StringReplace(@AutoItExe, "autoit3.exe", "ExamplesGUITorus.png")

Global $hBmp = ScaleImage($sFile, $fScaleW, $fScaleH)

Global $iW = _GDIPlus_ImageGetWidth($hBmp)
Global $iH = _GDIPlus_ImageGetHeight($hBmp)

Global $hGUI = GUICreate("GDI+ Image scaled to 250 %", $iW, $iH)
GUISetState()

Global $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI)
_GDIPlus_GraphicsDrawImage($hGraphics, $hBmp, 0, 0)
_GDIPlus_BitmapDispose($hBmp)

Do
Until GUIGetMsg() = - 3

_GDIPlus_Shutdown()
Exit

Func ScaleImage($sFile, $iScaleW, $iScaleH, $iInterpolationMode = 7) ;coded by UEZ 2012
    If Not FileExists($sFile) Then Return SetError(1, 0, 0)
    Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    If @error Then Return SetError(2, 0, 0)
    Local $iWidth = _GDIPlus_ImageGetWidth($hImage) * $iScaleW
    Local $iHeight = _GDIPlus_ImageGetHeight($hImage) * $iScaleH
    Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromScan0", "int", $iWidth, "int", $iHeight, "int", 0, "int", 0x0026200A, "ptr", 0, "int*", 0)
    If @error Then Return SetError(3, 0, 0)
    $hBitmap = $hBitmap[6]
    Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap)
    DllCall($ghGDIPDll, "uint", "GdipSetInterpolationMode", "handle", $hBmpCtxt, "int", $iInterpolationMode)
    _GDIPlus_GraphicsDrawImageRect($hBmpCtxt, $hImage, 0, 0, $iWidth, $iHeight)
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hBmpCtxt)
    Return $hBitmap
EndFunc

Br,

UEZ

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

You're the Boss! ;D

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