Crée un objet bitmap à partir d'un fichier image
#include <GDIPlus.au3>
_GDIPlus_BitmapCreateFromFile ( $sFileName )
$sFileName | Nom complet du fichier image. Les formats supportés par GDIPlus sont BMP, GIF, JPEG, PNG, TIFF, EXIF, WMF et EMF. |
Succès: | Retourne le handle de l'objet bitmap |
Échec: | Retourne 0 et définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*). |
Lorsque vous en avez terminé avec l'objet bitmap, appelez _GDIPlus_BitmapDispose() pour libérer les ressources.
_GDIPlus_BitmapDispose, _WinAPI_DeleteObject
Consultez GdipCreateBitmapFromFile dans la Librairie MSDN.
#include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <ScreenCapture.au3> #include <WinAPIHObj.au3> Example() Func Example() Local $hGUI, $hBMP, $hBitmap, $hGraphic, $hImage, $iX, $iY, $hClone ; Crée GUI $hGUI = GUICreate("GDI+", 400, 300) GUISetState(@SW_SHOW) ; Initialise la bibliothèque GDI + _GDIPlus_Startup() ; Capture un bitmap 32 bits $hBMP = _ScreenCapture_Capture("") $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP) ; Crée un clone du bitmap en 24 bits $iX = _GDIPlus_ImageGetWidth($hImage) $iY = _GDIPlus_ImageGetHeight($hImage) $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $GDIP_PXF24RGB) ; Enregistre le bitmap dan uns fichier _GDIPlus_ImageSaveToFile($hClone, @MyDocumentsDir & "\GDIPlus_Image.bmp") ; Nettoie les ressources _GDIPlus_BitmapDispose($hClone) _GDIPlus_BitmapDispose($hImage) _WinAPI_DeleteObject($hBMP) ; Dessine le bitmap dan la GUI $hBitmap = _GDIPlus_BitmapCreateFromFile(@MyDocumentsDir & "\GDIPlus_Image.bmp") $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI) _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0) ; Nettoie les ressources _GDIPlus_GraphicsDispose($hGraphic) _GDIPlus_BitmapDispose($hBitmap) ; Arrête la bibliothèque GDI + _GDIPlus_Shutdown() ; Boucle jusqu'à ce que l'utilisateur quitte. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE EndFunc ;==>Example
; PNG work around by UEZ #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WinAPIHObj.au3> ; Crée une GUI Local $hMainGUI = GUICreate("Show PNG", 210, 210) _GUICtrlPic_Create("..\GUI\Torus.png", 10, 10);, 100, 100) GUISetState(@SW_SHOW) ; Boucle jusqu'à ce que l'utilisateur quitte. While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd ; #INTERNAL_USE_ONLY#================================================================================================ ; Name...........: _GUICtrlPic_Create ; Description ...: Crée un contrôle Picture pour la GUI ; Syntax ........: _GUICtrlPic_Create($sFilename, $iLeft, $iTop, $iWidth, $iHeight, $iStyle = -1 , $iExStyle = -1) ; Parameters ....: $sFilename - Chemin du fichier image ; Author ........: UEZ ; Modified.......: Melba23, guinness, jpm ; Remarks .......: Une image .PNG peut être utilisée. ; ==================================================================================================================== Func _GUICtrlPic_Create($sFilename, $iLeft, $iTop, $iWidth = -1, $iHeight = -1, $iStyle = -1, $iExStyle = -1) _GDIPlus_Startup() Local $idPic = GUICtrlCreatePic("", $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle) Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sFilename) If $iWidth = -1 Then $iWidth = _GDIPlus_ImageGetWidth($hBitmap) If $iHeight = -1 Then $iHeight = _GDIPlus_ImageGetHeight($hBitmap) Local $hBitmap_Resized = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight) Local $hBMP_Ctxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_Resized) _GDIPlus_GraphicsSetInterpolationMode($hBMP_Ctxt, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC) _GDIPlus_GraphicsDrawImageRect($hBMP_Ctxt, $hBitmap, 0, 0, $iWidth, $iHeight) Local $hHBitmap = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap_Resized) Local $hPrevImage = GUICtrlSendMsg($idPic, $STM_SETIMAGE, 0, $hHBitmap) ; $STM_SETIMAGE = 0x0172 _WinAPI_DeleteObject($hPrevImage); Supprime PrevImage _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_BitmapDispose($hBitmap_Resized) _GDIPlus_GraphicsDispose($hBMP_Ctxt) _WinAPI_DeleteObject($hHBitmap) _GDIPlus_Shutdown() Return $idPic EndFunc ;==>_GUICtrlPic_Create