UDF > GDIPlus > Bitmap >


_GDIPlus_BitmapCreateFromResource

Crée un objet bitmap à partir d'une ressource d'une application ou d'une DLL

#include <GDIPlus.au3>
_GDIPlus_BitmapCreateFromResource ( $hInst, $vResourceName )

Paramètres

$hInst Handle d'une instance d'un module dont le fichier exécutable contient une ressource bitmap
$vResourceName La chaîne du nom de la ressource ou l'identifiant de la ressource

Valeur de retour

Succès: Retourne le handle du nouvel objet Bitmap.
Échec: Retourne 0 et définit @error <> 0, @extended contient le code erreur GPSTATUS ($GPID_ERR*).

Remarque

Lorsque vous en avez terminé avec l'objet, appelez _GDIPlus_ImageDispose() pour libérer les ressources de l'objet.

En relation

_GDIPlus_ImageDispose, _WinAPI_GetModuleHandle

Voir aussi

Consultez GdipCreateBitmapFromResource dans la Librairie MSDN.

Exemple

#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <WinAPIRes.au3>

Example()

Func Example()

    _GDIPlus_Startup() ; Initialise GDI+
    Local Const $iWidth = 300, $iHeight = 300, $iBgColor = 0x404040 ; $iBgColor est au format RRGGBB

    Local $hGUI = GUICreate("GDI+ example", $iWidth, $iHeight) ; Crée une GUI de test
    GUISetBkColor($iBgColor, $hGUI) ; Définit la couleur de fond de la GUI
    GUISetState(@SW_SHOW)

    Local $sAut2Exe = StringRegExpReplace(@AutoItExe, "\\\w+.exe", "\\Aut2Exe\\Aut2Exe.exe") ; Obtient le chemin vers le fichier Aut2Exe.exe
    If @AutoItX64 Then $sAut2Exe = StringRegExpReplace(@AutoItExe, "\\\w+.exe", "\\Aut2Exe\\Aut2Exe_X64.exe")

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ; Crée un objet graphique à partir d'un handle de fenêtre
    Local $hInst = _WinAPI_LoadLibrary($sAut2Exe) ; Mappe un module exécutable spécifié dans l'espace d'adressage du processus appelant
    Local $hBitmap = _GDIPlus_BitmapCreateFromResource($hInst, "BMP_MAINLOGO") ; Charge la ressource bitmap "BMP_MAINLOGO" et la convertit au format bitmap GDI+
    Local $iW = _GDIPlus_ImageGetWidth($hBitmap), $iH = _GDIPlus_ImageGetHeight($hBitmap)
    _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, ($iWidth - $iW) / 2, ($iHeight - $iH) / 2) ; Affiche l'image dans la GUI centrée

    Do
    Until GUIGetMsg() = $GUI_EVENT_CLOSE

    ; Nettoie les ressources GDI+
    _WinAPI_FreeLibrary($hInst)
    _GDIPlus_BitmapDispose($hBitmap)
    _GDIPlus_GraphicsDispose($hGraphics)
    _GDIPlus_Shutdown()
    GUIDelete($hGUI)
    Exit
EndFunc   ;==>Example