Function Reference


_GDIPlus_ImageLoadFromFile

Create an image object based on a file

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

Parameters

$sFileName Fully qualified image file name

Return Value

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

Related

_GDIPlus_ImageSaveToFile, _GDIPlus_ImageSaveToFileEx

See Also

Search GdipLoadImageFromFile in MSDN Library.

Example

Example 1

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

Example()

Func Example()
        Local $hImage, $sCLSID, $tData, $tParams

        ; Screen Capture
        _ScreenCapture_Capture(@MyDocumentsDir & "\GDIPlus_Image.jpg")

        ; Initialize GDI+ library
        _GDIPlus_Startup()

        ; Load image
        $hImage = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & "\GDIPlus_Image.jpg")

        ; Get JPEG encoder CLSID
        $sCLSID = _GDIPlus_EncodersGetCLSID("JPG")

        ; Set up parameters for 90 degree rotation
        $tData = DllStructCreate("int Data")
        DllStructSetData($tData, "Data", $GDIP_EVTTRANSFORMROTATE90)
        $tParams = _GDIPlus_ParamInit(1)
        _GDIPlus_ParamAdd($tParams, $GDIP_EPGTRANSFORMATION, 1, $GDIP_EPTLONG, DllStructGetPtr($tData, "Data"))

        ; Save image with rotation
        _GDIPlus_ImageSaveToFileEx($hImage, @MyDocumentsDir & "\GDIPlus_Image2.jpg", $sCLSID, $tParams)

        ; Clean up resources
        _GDIPlus_ImageDispose($hImage)

        ; Shut down GDI+ library
        _GDIPlus_Shutdown()

        ShellExecute(@MyDocumentsDir & "\GDIPlus_Image2.jpg")
EndFunc   ;==>Example

Example 2

; PNG work around by Zedna

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

; Create GUI
Global $g_hGUI = GUICreate("Show PNG", 250, 250)

; Load PNG image
_GDIPlus_Startup()
Global $g_hImage = _GDIPlus_ImageLoadFromFile("..\GUI\Torus.png")
Global $g_hGraphic = _GDIPlus_GraphicsCreateFromHWND($g_hGUI)

GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT")
GUISetState(@SW_SHOW)

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

        EndSwitch
WEnd

; Clean up resources
_GDIPlus_GraphicsDispose($g_hGraphic)
_GDIPlus_ImageDispose($g_hImage)
_GDIPlus_Shutdown()

; Draw PNG image
Func MY_WM_PAINT($hWnd, $iMsg, $wParam, $lParam)
        #forceref $hWnd, $iMsg, $wParam, $lParam
        _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_UPDATENOW)
        _GDIPlus_GraphicsDrawImage($g_hGraphic, $g_hImage, 0, 0)
        _WinAPI_RedrawWindow($g_hGUI, 0, 0, $RDW_VALIDATE)
        Return $GUI_RUNDEFMSG
EndFunc   ;==>MY_WM_PAINT