Function Reference


_GDIPlus_BitmapCreateFromFile

Create a Bitmap object from file

#include <GDIPlus.au3>
_GDIPlus_BitmapCreateFromFile ( $sFileName )

Parameters

$sFileName Path to a bitmap file

Return Value

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

Remarks

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

Related

_GDIPlus_BitmapDispose, _WinAPI_DeleteObject

See Also

Search GdipCreateBitmapFromFile in MSDN Library.

Example

Example 1

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

Example()

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

        ; Create GUI
        $hGUI = GUICreate("GDI+", 400, 300)
        GUISetState(@SW_SHOW)

        ; Initialize GDI+ library
        _GDIPlus_Startup()

        ; 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, @MyDocumentsDir & "\GDIPlus_Image.bmp")

        ; Clean up resources
        _GDIPlus_BitmapDispose($hClone)
        _GDIPlus_BitmapDispose($hImage)
        _WinAPI_DeleteObject($hBMP)

        ; Draw bitmap to GUI
        $hBitmap = _GDIPlus_BitmapCreateFromFile(@MyDocumentsDir & "\GDIPlus_Image.bmp")
        $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
        _GDIPlus_GraphicsDrawImage($hGraphic, $hBitmap, 0, 0)

        ; Clean up resources
        _GDIPlus_GraphicsDispose($hGraphic)
        _GDIPlus_BitmapDispose($hBitmap)

        ; Shut down GDI+ library
        _GDIPlus_Shutdown()

        ; Loop until the user exits.
        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Example 2

; PNG work around by UEZ

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

; Create GUI
Local $hMainGUI = GUICreate("Show PNG", 210, 210)

_GUICtrlPic_Create("..\GUI\Torus.png", 10, 10);, 100, 100)

GUISetState(@SW_SHOW)

; Loop until the user exits.
While 1
        Switch GUIGetMsg()
                Case $GUI_EVENT_CLOSE
                        ExitLoop

        EndSwitch
WEnd

; #INTERNAL_USE_ONLY#=================================================================================================
; Name...........: _GUICtrlPic_Create
; Description ...: Creates a Picture control for the GUI
; Syntax ........: _GUICtrlPic_Create($sFilename, $iLeft, $iTop, $iWidth, $iHeight, $iStyle = -1 , $iExStyle = -1)
; Parameters ....: $sFilename - Path of image file
; Author ........: UEZ
; Modified.......: Melba23, guinness, jpm
; Remarks .......: PNG image can be used.
; ====================================================================================================================
Func _GUICtrlPic_Create($sFilename, $iLeft, $iTop, $iWidth = -1, $iHeight = -1, $iStyle = -1, $iExStyle = -1)
        _GDIPlus_Startup()
        Local $idPic = GUICtrlCreatePic("", $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle)
        Local $hBitmap = _GDIPlus_BitmapCreateFromFile($sFilename)
        If $iWidth = -1 Then $iWidth = _GDIPlus_ImageGetWidth($hBitmap)
        If $iHeight = -1 Then $iHeight = _GDIPlus_ImageGetHeight($hBitmap)
        Local $hBitmap_Resized = _GDIPlus_BitmapCreateFromScan0($iWidth, $iHeight)
        Local $hBMP_Ctxt = _GDIPlus_ImageGetGraphicsContext($hBitmap_Resized)
        _GDIPlus_GraphicsSetInterpolationMode($hBMP_Ctxt, $GDIP_INTERPOLATIONMODE_HIGHQUALITYBICUBIC)
        _GDIPlus_GraphicsDrawImageRect($hBMP_Ctxt, $hBitmap, 0, 0, $iWidth, $iHeight)
        Local $hHBitmap = _GDIPlus_BitmapCreateDIBFromBitmap($hBitmap_Resized)
        Local $hPrevImage = GUICtrlSendMsg($idPic, $STM_SETIMAGE, 0, $hHBitmap) ; $STM_SETIMAGE = 0x0172
        _WinAPI_DeleteObject($hPrevImage); Delete Prev image if any
        _GDIPlus_BitmapDispose($hBitmap)
        _GDIPlus_BitmapDispose($hBitmap_Resized)
        _GDIPlus_GraphicsDispose($hBMP_Ctxt)
        _WinAPI_DeleteObject($hHBitmap)
        _GDIPlus_Shutdown()

        Return $idPic
EndFunc   ;==>_GUICtrlPic_Create