# Function Reference

# _GDIPlus_BitmapCreateFromMemory

Loads an image (JPG, BMP, PNG, etc.) which is saved as a binary string and converts it to a bitmap (GDI+) or hbitmap (GDI)

#include <GDIPlus.au3>
_GDIPlus_BitmapCreateFromMemory ( $dImage [, $bHBITMAP = False] )

## Parameters

$dImage | The binary string which contains any valid image which is supported by GDI+
$bHBITMAP | [optional] If False a bitmap will be created, if True a hbitmap (GDI) will be created

## Return Value

Success: | a handle to bitmap (GDI+ bitmap format) or hbitmap (WinAPI bitmap format).
Failure: | 0 and sets the @error flag to non-zero.
@error: | 1 - $dImage is not a binary string 2 - unable to create stream on HGlobal 3 - unable to create bitmap from stream 4 - unable to allocate moveable memory block 5 - unable to lock moveable memory block 6 - unable to unlock locked moveable memory block

## Remarks

After you are done with the object, call _GDIPlus_ImageDispose() to release the object resources.

## Related

_GDIPlus_BitmapCreateFromStream, _GDIPlus_BitmapDispose

## See Also

Search CreateDIBSection in MSDN Library.

## Example

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

    Example()

    Func Example()
        _GDIPlus_Startup() ;initialize GDI+
        Local Const $iWidth = 300, $iHeight = 300, $iBgColor = 0xFFE8FF ;$iBgColor format RRGGBB

        Local $hGUI = GUICreate("GDI+ Example (" & @ScriptName & ")", $iWidth, $iHeight) ;create a test GUI
        GUISetBkColor($iBgColor, $hGUI) ;set GUI background color
        GUISetState(@SW_SHOW)

        Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
        Local $hBitmap = _GDIPlus_BitmapCreateFromMemory(BinGIFImage()) ;load binary saved GIF image and convert it to GDI+ bitmap format
        Local $iW = _GDIPlus_ImageGetWidth($hBitmap), $iH = _GDIPlus_ImageGetHeight($hBitmap)
        _GDIPlus_GraphicsDrawImage($hGraphics, $hBitmap, ($iWidth - $iW) / 2, ($iHeight - $iH) / 2) ;display image in GUI

        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        ;cleanup GDI+ resources
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_Shutdown()
        GUIDelete($hGUI)
    EndFunc   ;==>Example

    Func BinGIFImage() ;test GIF image converted to a binary string
        Local $sBinGIFImage = ' '
        $sBinGIFImage &= ' '
        $sBinGIFImage &= ' '
        Return Binary($sBinGIFImage)
    EndFunc   ;==>BinGIFImage