Sign in to follow this  
Followers 0
Achilles

Resizing Images - possible with _GDI* functions?

4 posts in this topic

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?


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
Share on other sites

I should have searched before I posted... Sometimes I just get random ideas and forget to wonder if other people have tried them before. Anyway, thanks UEZ that was just what I was looking for.


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

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