Sign in to follow this  
Followers 0
AlmarM

Resized a loaded jpg file

8 posts in this topic

Hiya!

Is there a way to: Load a .jpg file, resize it and save the resized image using GDIPlus? Or any other method?

AlmarM :mellow:


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites



It can be done fairly easy and simple by using mspaint

Share this post


Link to post
Share on other sites

It should be fully automatic, without any notice the image is actualy resized.

Im currently using FreeImage.

$SelectPic = FileOpenDialog("Select picture...", @DesktopDir, "JPG Pictures (*.jpg;*.jpeg)", 3, "", $MainGUI)
    _FreeImage_LoadDLL(@ScriptDir & "\Resources\FreeImage.dll")
    _FreeImage_Initialise()

    $FIF = _FreeImage_GetFileTypeU($SelectPic)
    If $FIF = $FIF_UNKNOWN Then
        $FIF = _FreeImage_GetFIFFromFilenameU($SelectPic)
    EndIf
    $hImage = _FreeImage_LoadU($FIF, $SelectPic)
    $Resized = _FreeImage_Rescale($hImage, 320, 460, $FILTER_LANCZOS3)
    _FreeImage_SaveU($FIF, $Resized, $PicResized)
    _FreeImage_Unload($hImage)
    _FreeImage_Unload($Resized)
    _FreeImage_DeInitialise()

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

You could use ImageMagick.

Eh? Whats ImageMagick?

I dont need any software, its just like this:

The user selects a JPG file using FileOpenDialog, autoit should load it, resize it and then save it agian.


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Im currently trying something like this.

#include <GDIPlus.au3>

$fod = FileOpenDialog("", @DesktopDir, "All files (*.*)")
$fsd = FileSaveDialog("", @DesktopDir, "All files (*.*)")

_ResizeImage($fod, $fsd, 100, 100)

Func _ResizeImage($sFile, $sOutput, $iWidth, $iHeight)
    _GDIPlus_Startup()
    
    $hImage = _GDIPlus_ImageLoadFromFile($sFile)
    
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage)
    
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage, 0, 0, $iWidth, $iHeight)
    _GDIPlus_ImageSaveToFile($hImage, $sOutput)
    
    _GDIPlus_ImageDispose($hImage)
    _GDIPlus_GraphicsDispose($hGraphic)
    
    _GDIPlus_Shutdown()
EndFunc

Isnt working though.


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

This works.

#include <GDIPlus.au3>

Local $fod = FileOpenDialog("", @DesktopDir, "All files (*.*)")
Local $fsd = FileSaveDialog("", @DesktopDir, "All files (*.*)")

_ResizeImage($fod, $fsd, 100, 100)

ShellExecute($fsd)

Func _ResizeImage($sFile, $sOutput, $iWidth, $iHeight)
    Local $hBMP, $hImage1, $hImage2, $hGraphic
    _GDIPlus_Startup()
    $hBMP = _WinAPI_CreateBitmap($iWidth, $iHeight, 1, 32) ; Create a bitmap (handle)
    $hImage1 = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)  ; Create a Bitmap object from a bitmap handle.
    $hGraphic = _GDIPlus_ImageGetGraphicsContext($hImage1) ; Get the graphic context of the blank bitmap.
    $hImage2 = _GDIPlus_ImageLoadFromFile($sFile)   ; Load the image you want to resize.
    _GDIPlus_GraphicsDrawImageRect($hGraphic, $hImage2, 0, 0, $iWidth, $iHeight) ;Draw the loaded image to the graphics of the blank bitmap at the size you want.
    _GDIPlus_ImageSaveToFile($hImage1, $sOutput)

    _GDIPlus_ImageDispose($hImage1)
    _GDIPlus_ImageDispose($hImage2)
    _GDIPlus_GraphicsDispose($hGraphic)
    _WinAPI_DeleteObject($hBMP)
    _GDIPlus_Shutdown()
EndFunc ;==>_ResizeImage

Share this post


Link to post
Share on other sites

Thanks :mellow:


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

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