Function Reference


Create a handle to a bitmap from a bitmap object

#include <GDIPlus.au3>
_GDIPlus_BitmapCreateHBITMAPFromBitmap ( $hBitmap [, $iARGB = 0xFF000000] )


$hBitmap Handle to a bitmap object
$iARGB [optional] Color object that specifies the background color

Return Value

Success: a handle to a HBITMAP.
Failure: 0 and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPIP_ERR* see GPIPlusConstants.au3).


When you are done with the Bitmap object, call _WinAPI_DeleteObject() to release the resources.



See Also

Search GdipCreateHBITMAPFromBitmap in MSDN Library.


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


Func Example()
        Local $hBMP, $hImage, $iX, $iY, $hClone

        ; Initialize GDI+ library

        ; Capture 32 bit bitmap
        $hBMP = _ScreenCapture_Capture("")
        $hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBMP)

        ; Create 24 bit bitmap clone
        $iX = _GDIPlus_ImageGetWidth($hImage)
        $iY = _GDIPlus_ImageGetHeight($hImage)
        $hClone = _GDIPlus_BitmapCloneArea($hImage, 0, 0, $iX, $iY, $GDIP_PXF24RGB)

        ; Save bitmap to file
        _GDIPlus_ImageSaveToFile($hClone, @TempDir & "\GDIPlus_Image.bmp")

        ; Clean up resources

        ; Load image
        $hImage = _GDIPlus_ImageLoadFromFile(@TempDir & "\GDIPlus_Image.bmp")
        $hBMP = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)

        ; Save bitmap to file
        _ScreenCapture_SaveImage(@TempDir & "\Image.bmp", $hBMP, True) ; True -> $hBMP destroyed

        ; Clean up resource

        ; Shut down GDI+ library
EndFunc   ;==>Example