;coded by UEZ 2010
#include <GDIplus.au3>
#include <GUIConstantsEx.au3>
#Include <Memory.au3>
_GDIPlus_Startup()
Local $hImage = Load
_BMP
_From
_Mem
(InetRead("<a href='http://www.autoitscript.com/forum/public/style_images/autoit/logo.png' class='bbc_url' title=''>http://www.autoitscript.com/forum/public/style_images/autoit/logo.png"</a
>))
Local $iWidth = _GDIPlus_ImageGetWidth($hImage)
Local $iHeight = _GDIPlus_ImageGetHeight($hImage)
Local $hWnd = GUICreate("Display image from memory by UEZ 2010", $iWidth, $iHeight)
GUISetState(@SW_SHOW)
Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hWnd)
_GDIPlus_GraphicsDrawImageRect ($hGraphics, $hImage, 0, 0, $iWidth, $iHeight);copy bitmap to GUI
GUISetState()
GUIRegisterMsg(0x0014, "WM_ERASEBKGND")
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_GDIPlus_ImageDispose($hImage)
_GDIPlus_GraphicsDispose($hGraphics)
_GDIPlus_Shutdown()
GUIDelete($hWnd)
Exit
EndSwitch
WEnd
Func WM
_ERASEBKGND
($hWnd, $uMsgm, $wParam, $lParam)
_GDIPlus_GraphicsDrawImageRect ($hGraphics, $hImage, 0, 0, $iWidth, $iHeight)
Return True
EndFunc ;==>WM_ERASEBKGND
;======================================================================================
; Function Name: Load_BMP_From_Mem
; Description: Loads a image which is saved as a binary string and converts it to a bitmap or hbitmap
;
; Parameters: $mem_image: 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
;
; Requirement(s): GDIPlus.au3, Memory.au3
; Return Value(s): Success: handle to bitmap or hbitmap, Error: 0
; Error codes: 1: $mem_image 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-11 Beta
;=======================================================================================
Func Load
_BMP
_From
_Mem
($mem_image, $hHBITMAP = False)
If Not IsBinary($mem_image) Then Return SetError(1, 0, 0)
Local $declared = True
If Not $ghGDIPDll Then
_GDIPlus_Startup()
$declared = False
EndIf
Local Const $memBitmap = Binary($mem_image) ;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
Save to disk not needed.