Code : Tout sélectionner
#include <GDIPlus.au3>
#include <File.au3>
#include <Array.au3>
$newFileName = "C:\Users\Pc\Desktop\decompo\path11.png"
$holdFileName = "C:\Users\Pc\Desktop\path1S.png"
$W = 402
$H = 419
_Image($holdFileName, $newFileName, $W, $H)
; Resize function
Func _Image($sInImage, $sOutImage, $iW, $iH)
Local $hWnd, $hDC, $hBMP, $hImage1, $hImage2, $hGraphic, $CLSID, $i = 0
;OutFile path, to use later on.
Local $sOP = StringLeft($sOutImage, StringInStr($sOutImage, "\", 0, -1))
;OutFile name, to use later on.
Local $sOF1 = StringMid($sOutImage, StringInStr($sOutImage, "\", 0, -1) + 1)
Local $sOF = StringMid($sOF1,1,StringInStr($sOF1, ".", 0, 1) - 1) & "-"
;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)
$hImage1 = _GDIPlus_ImageLoadFromFile("C:\Users\Pc\Desktop\g6.png") ;Base
;Load the image you want to resize.
$hImage2 = _GDIPlus_ImageLoadFromFile($sInImage)
;Get the graphic context of the blank bitmap
$hGraphic = _GDIPlus_ImageGetGraphicsContext ($hImage1)
Local $hIA = _GDIPlus_ImageAttributesCreate() ;create an ImageAttribute object >> transparence
_GDIPlus_ImageAttributesSetColorKeys($hIA, 0, True, 0x00400000, 0x00ffff00)
_GDIPlus_GraphicsDrawImageRectRect($hGraphic, $hImage2, 0, 0, $iW, $iH, 0, 0, $iW, $iH, $hIA)
$CLSID = _GDIPlus_EncodersGetCLSID("png")
;Generate a number for out file that doesn't already exist, so you don't overwrite an existing image.
Local $i
Do
$i += 1
$y = StringFormat("%03i",$i)
Until (Not FileExists($sOP & $sOF & $y & "." & $Ext))
;Prefix the number to the begining of the output filename
$sOutImage = $sOP & $sOF & $y & "." & $Ext
;Save the new resized image.
_GDIPlus_ImageSaveToFileEx($hImage1, $sOutImage, $CLSID)
;_GDIPlus_ImageSaveToFile($hImage1, $sOutImage)
;Clean up and shutdown GDIPlus.
_GDIPlus_ImageDispose($hImage1)
_GDIPlus_ImageDispose($hImage2)
_GDIPlus_GraphicsDispose ($hGraphic)
_WinAPI_DeleteObject($hBMP)
_GDIPlus_ImageAttributesDispose($hIA)
_GDIPlus_Shutdown()
EndFunc