Function Reference


Creates an Image object based on a stream

#include <GDIPlus.au3>
_GDIPlus_ImageLoadFromStream ( $pStream )


$pStream Pointer to an IStream interface

Return Value

Success: a pointer to a new Image object.
Failure: 0 and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*).


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



See Also

Search GdipLoadImageFromStream in MSDN Library.


#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WinAPICom.au3>
#include <WinAPIConv.au3>
#include <WinAPIHObj.au3>


Func Example()
    Local Const $iW = @DesktopWidth / 2, $iH = @DesktopHeight / 2
    Local $hGUI = GUICreate("GDI+ test", $iW, $iH, -1, -1)

    Local $hHBmp = _ScreenCapture_Capture("", 0, 0, @DesktopWidth / 2, @DesktopHeight / 2) ;create a GDI bitmap by capturing 1/4 of desktop
    Local $hBitmap = _GDIPlus_BitmapCreateFromHBITMAP($hHBmp) ;convert GDI bitmap to GDI+ bitmap
    _WinAPI_DeleteObject($hHBmp) ;release GDI bitmap resource because not needed anymore

    Local $sImgCLSID = _GDIPlus_EncodersGetCLSID("jpg") ;create CLSID for a JPG image file type
    Local $tGUID = _WinAPI_GUIDFromString($sImgCLSID) ;convert CLSID GUID to binary form and returns $tagGUID structure
    Local $tParams = _GDIPlus_ParamInit(1) ;initialize an encoder parameter list and return $tagGDIPENCODERPARAMS structure
    Local $tData = DllStructCreate("int Quality") ;create struct to set JPG quality setting
    DllStructSetData($tData, "Quality", 10) ;quality 0-100 (0: lowest, 100: highest)
    Local $pData = DllStructGetPtr($tData) ;get pointer from quality struct
    _GDIPlus_ParamAdd($tParams, $GDIP_EPGQUALITY, 1, $GDIP_EPTLONG, $pData) ;add a value to an encoder parameter list
    Local $pParams = DllStructGetPtr($tParams) ;get pointer of encoder parameter list
    Local $pStream = _WinAPI_CreateStreamOnHGlobal() ;create stream
    _GDIPlus_ImageSaveToStream($hBitmap, $pStream, $tGUID, $pParams) ;save the bitmap in JPG format in memory
    Local $hImageFromStream = _GDIPlus_ImageLoadFromStream($pStream) ;create bitmap from a stream (here from the JPG in memory)

    Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGUI) ;create a graphics object from a window handle
    _GDIPlus_GraphicsDrawImage($hGraphics, $hImageFromStream, 0, 0) ;display streamed image

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE

    ;cleanup resources
EndFunc   ;==>Example