Function Reference


Returns pixel format of an image: Bits per pixel, Alpha channels, RGB, Grayscale, Indexed etc

#include <GDIPlus.au3>
_GDIPlus_ImageGetPixelFormat ( $hImage )


$hImage Handle to an image object

Return Value

Success: an array with the following format:
    [0] - Integer of pixel format constant
    [1] - String of pixel format
Failure: sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GPID_ERR*).
@error: 10 - Invalid pixel format.
11 - Invalid image handle.
12 - Unknown pixel format.


_GDIPlus_BitmapCloneArea, _GDIPlus_BitmapLockBits, _GDIPlus_ImageGetFlags

See Also

Search GdipGetImagePixelFormat in MSDN Library.


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

Global $g_idMemo


Func Example()
    Local $hBitmap, $hImage, $aRet

    ; Create GUI
    GUICreate("GDI+", 600, 400)
    $g_idMemo = GUICtrlCreateEdit("", 2, 2, 596, 396, $WS_VSCROLL)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")

    ; Initialize GDI+ library

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

    ; Show pixel format for screen capture
    $aRet = _GDIPlus_ImageGetPixelFormat($hImage)
    MemoWrite("Image pixel format of screen capture: " & $aRet[1]);
    MemoWrite("Image pixel format constant: " & $aRet[0]);

    ; Save screen capture bitmap to file
    _GDIPlus_ImageSaveToFile($hImage, @MyDocumentsDir & "\GDIPlus_Image.jpg")

    ; Clean up resources

    ; Load screen capture bitmap from file
    $hImage = _GDIPlus_ImageLoadFromFile(@MyDocumentsDir & "\GDIPlus_Image.jpg")

    ; Show pixel format for saved file
    $aRet = _GDIPlus_ImageGetPixelFormat($hImage)
    MemoWrite("Image pixel format of saved file: " & $aRet[1]);
    MemoWrite("Image pixel format constant: " & $aRet[0]);

    ; Clean up resources

    ; Shut down GDI+ library

    ; Loop until the user exits.
    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