Returns type (bitmap or metafile) of an image
#include <GDIPlus.au3>
_GDIPlus_ImageGetType ( $hImage )
$hImage | Handle to an image object |
Success: | an integer of image type: $GDIP_IMAGETYPE_UNKNOWN - Non bitmap file or not identified as bitmap by GDI+ $GDIP_IMAGETYPE_BITMAP - Bitmap types: BMP, PNG, GIF, JPEG, TIFF, ICO, EXIF $GDIP_IMAGETYPE_METAFILE - Metafile types: EMF, WMF |
Failure: | -1 and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPIP_ERR* see GPIPlusConstants.au3). |
@error: | 10 - Invalid image type. 11 - Invalid image handle. |
Search GdipGetImageType in MSDN Library.
#include <GDIPlus.au3>
#include <GUIConstantsEx.au3>
#include <ScreenCapture.au3>
#include <WinAPIHObj.au3>
#include <WindowsConstants.au3>
Global $g_idMemo
Example()
Func Example()
Local $hBitmap, $hImage, $iImageType, $sImageType
; Create GUI
GUICreate("GDI+", 600, 400)
$g_idMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, $WS_VSCROLL)
GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
GUISetState(@SW_SHOW)
; Initialize GDI+ library
_GDIPlus_Startup()
; Capture 32 bit bitmap
$hBitmap = _ScreenCapture_Capture("")
$hImage = _GDIPlus_BitmapCreateFromHBITMAP($hBitmap)
$iImageType = _GDIPlus_ImageGetType($hImage)
Switch $iImageType
Case $GDIP_IMAGETYPE_UNKNOWN
$sImageType = "Unrecognized bitmap format or not image file"
Case $GDIP_IMAGETYPE_BITMAP ; BMP, PNG, GIF, JPEG, TIFF, ICO, EXIF
$sImageType = "Bitmap"
Case $GDIP_IMAGETYPE_METAFILE ; EMF, WMF
$sImageType = "Metafile"
EndSwitch
; Show image type: Unidentified = 0, Bitmap = 1, Metafile = 2)
MemoWrite("Image type: " & $sImageType);
; Clean up resources
_GDIPlus_ImageDispose($hImage)
_WinAPI_DeleteObject($hBitmap)
; Shut down GDI+ library
_GDIPlus_Shutdown()
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc ;==>Example
; Write a line to the memo control
Func MemoWrite($sMessage = '')
GUICtrlSetData($g_idMemo, $sMessage & @CRLF, 1)
EndFunc ;==>MemoWrite