Function Reference


Saves an Image object to a stream

#include <GDIPlus.au3>
_GDIPlus_ImageSaveToStream ( $hImage, $pStream, $tEncoder [, $tParams = 0] )


$hImage Pointer to an Image object
$pStream Pointer to an IStream interface
$tEncoder a $tagGUID structure that defines the image encoder GUID
$tParams [optional] a $tagGDIPENCODERPARAMS structure or a pointer to it

Return Value

Success: True.
Failure: False and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*).


Use this function to save selected frames from a multiple-frame image to another multiple-frame image.


$tagGDIPENCODERPARAMS, _GDIPlus_EncodersGetCLSID, _GDIPlus_ImageLoadFromStream, _GDIPlus_ImageSaveToFile

See Also

Search GdipSaveImageToStream 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 $pStream = _WinAPI_CreateStreamOnHGlobal() ;create stream
    _GDIPlus_ImageSaveToStream($hBitmap, $pStream, $tGUID, $tParams) ;save the bitmap in JPG format in memory
    Local $hBitmapFromStream = _GDIPlus_BitmapCreateFromStream($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, $hBitmapFromStream, 0, 0) ;display streamed image

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE

    ;cleanup resources
EndFunc   ;==>Example