Jump to content

Resizing Images - possible with _GDI* functions?


Recommended Posts

I want to resize an image that is say 1600x1200 to say 400x300. Is this possible with only GDIPlus functions? I've looked at some of the functions but don't see how I could make it work. Any ideas?

Here a very simple GDI+ example:

#include <GDIplus.au3>
#include <GuiConstantsEx.au3>
Opt('MustDeclareVars', 1)

Global $file, $msg

Do
    $file = FileOpenDialog("Select Image to load", @ScriptDir, "Images (*.jpg;*.png; *.bmp;*.gif)")
    If @error Then
    $msg = MsgBox(20, "Error", "Please select an image!")
    If $msg = 7 Then
    Exit
    Else
    SetError(1)
    EndIf
    EndIf
Until Not @error
_GDIPlus_Startup()
Global $hImage = _GDIPlus_BitmapCreateFromFile($file)
Global $iX = _GDIPlus_ImageGetWidth($hImage)
Global $iY = _GDIPlus_ImageGetHeight($hImage)
Global $resize_factor = 0.5
Global $hwnd = GUICreate("GDI+: Image resized to " & $iX * $resize_factor & "x" & $iY * $resize_factor, $iX * $resize_factor, $iY * $resize_factor, -1, -1)
GUISetState(@SW_SHOW)
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hwnd)
_GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iX * $resize_factor, $iY * $resize_factor)

While Sleep(30)
    Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
    _GDIPlus_GraphicsDispose($hGraphic)
    _GDIPlus_Shutdown()
    Exit
    EndSwitch
WEnd

I hope it helps!

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!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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