Cette fonction à été écrite par UEZ du forum Anglais et je l'ai trouvée sur ce sujet.
Vous trouverez un exemple d'utilisation de cette fonction sur ce lien : Le lien va arriver dés que j'aurais fini la rédaction de l'exemple ...

Code : Tout sélectionner
;======================================================================================
; Function Name: Load_BMP_From_Mem
; Description: Loads an image which is saved as a binary string and converts it to a bitmap or hbitmap
;
; Parameters: $bImage: the binary string which contains any valid image which is supported by GDI+
; Optional: $hHBITMAP: if false a bitmap will be created, if true a hbitmap will be created
;
; Remark: hbitmap format is used generally for GUI internal images, $bitmap is more a GDI+ image format
;
; Requirement(s): GDIPlus.au3, Memory.au3
; Return Value(s): Success: handle to bitmap or hbitmap, Error: 0
; Error codes: 1: $bImage is not a binary string
;
; Author(s): UEZ
; Additional Code: thanks to progandy for the MemGlobalAlloc and tVARIANT lines
; Version: v0.95 Build 2011-06-14 Beta
;=======================================================================================
Func Load_BMP_From_Mem($bImage, $hHBITMAP = False)
If Not IsBinary($bImage) Then Return SetError(1, 0, 0)
Local $declared = True
If Not $ghGDIPDll Then
_GDIPlus_Startup()
$declared = False
EndIf
Local Const $memBitmap = Binary($bImage) ;load image saved in variable (memory) and convert it to binary
Local Const $len = BinaryLen($memBitmap) ;get length of image
Local Const $hData = _MemGlobalAlloc($len, $GMEM_MOVEABLE) ;allocates movable memory ($GMEM_MOVEABLE = 0x0002)
Local Const $pData = _MemGlobalLock($hData) ;translate the handle into a pointer
Local $tMem = DllStructCreate("byte[" & $len & "]", $pData) ;create struct
DllStructSetData($tMem, 1, $memBitmap) ;fill struct with image data
_MemGlobalUnlock($hData) ;decrements the lock count associated with a memory object that was allocated with GMEM_MOVEABLE
Local $hStream = DllCall("ole32.dll", "int", "CreateStreamOnHGlobal", "handle", $pData, "int", True, "ptr*", 0)
$hStream = $hStream[3]
Local $hBitmap = DllCall($ghGDIPDll, "uint", "GdipCreateBitmapFromStream", "ptr", $hStream, "int*", 0) ;Creates a Bitmap object based on an IStream COM interface
$hBitmap = $hBitmap[2]
Local Const $tVARIANT = DllStructCreate("word vt;word r1;word r2;word r3;ptr data; ptr")
DllCall("oleaut32.dll", "long", "DispCallFunc", "ptr", $hStream, "dword", 8 + 8 * @AutoItX64, _
"dword", 4, "dword", 23, "dword", 0, "ptr", 0, "ptr", 0, "ptr", DllStructGetPtr($tVARIANT)) ;release memory from $hStream to avoid memory leak
$tMem = 0
If $hHBITMAP Then
Local Const $hHBmp = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap)
_GDIPlus_BitmapDispose($hBitmap)
If Not $declared Then _GDIPlus_Shutdown()
Return $hHBmp
EndIf
If Not $declared Then _GDIPlus_Shutdown()
Return $hBitmap
EndFunc ;==>Load_BMP_From_Mem