#include <GDIPlus.au3>
#include <Math.au3>
#include <Misc.au3>
_ImageResize("Rus.bmp","Rus_2.bmp",800,300)
Func _ImageResize($sInImage, $sOutImage, $iW, $iH,$iARGB = 0xFFFFFFFF)
Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $H, $W, $coff, $X = 0, $Y = 0
;OutFile extension , to use for the encoder later on.
Local $Ext = StringUpper(StringMid($sOutImage, StringInStr($sOutImage, ".", 0, -1) + 1))
; Win api to create blank bitmap at the width and height to put your resized image on.
$hWnd = _WinAPI_GetDesktopWindow()
$hDC = _WinAPI_GetDC($hWnd)
$hBMP = _WinAPI_CreateCompatibleBitmap($hDC, $iW, $iH)
_WinAPI_ReleaseDC($hWnd, $hDC)
;Start GDIPlus
_GDIPlus_Startup()
;Get the handle of blank bitmap you created above as an image
$hImage1 = _GDIPlus_BitmapCreateFromHBITMAP ($hBMP)
;Load the image you want to resize.
$hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)
$W = _GDIPlus_ImageGetWidth($hImage2)
$H = _GDIPlus_ImageGetHeight($hImage2)
;Get the graphic context of the blank bitmap
$hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1)
;Draw the loaded image onto the blank bitmap at the size you want
_GDIPlus_GraphicsClear($hGraphic,$iARGB)
$coff = _Iif($W>$H,(_Max($W,$iW)/_Min($W,$iW)),(_Max($H,$iH)/_Min($H,$iH)))
$W = Execute($W&_Iif($iW>$W,"*","/")&$coff)
$H = Execute($H&_Iif($iH<$H,"*","/")&$coff)
MsgBox(0,"","coff="&$coff&@CRLF&"W="&$W&@CRLF&"H="&$H&@CRLF&"X="&$X&@CRLF&"Y="&$Y)
_GDIPLus_GraphicsDrawImageRect($hGraphic, $hImage2, $X, $Y, $W, $H)
;Get the encoder of to save the resized image in the format you want.
$CLSID = _GDIPlus_EncodersGetCLSID($Ext)
;Save the new resized image.
_GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID)
;Clean up and shutdown GDIPlus.
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_GraphicsDispose ($hGraphic)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_Shutdown()
EndFunc