# Function Reference

# _GDIPlus_BitmapConvertFormat

Converts a bitmap to a specified pixel format

#include <GDIPlus.au3>
_GDIPlus_BitmapConvertFormat ( $hBitmap, $iPixelFormat, $iDitherType, $iPaletteType, $tPalette [, $fAlphaThresholdPercent = 0.0] )

## Parameters

$hBitmap | Handle to a Bitmap to which the effect is applied.
$iPixelFormat | Pixel format constant that specifies the new pixel format ($GDIP_PXF*).
$iDitherType | DitherType constant that specifies the dithering algorithm ($GDIP_DitherType*).
$iPaletteType | PaletteType constant that specifies a standard palette to be used for dithering ($GDIP_PaletteType*).
$tPalette | Structure that specifies the palette whose indexes are stored in the pixel data of the converted bitmap.
$fAlphaThresholdPercent | [optional] Real number in the range 0.0 through 100.0 that specifies which pixels in the source bitmap will map to the transparent color in the converted bitmap.

## Return Value

Success: | True.
Failure: | False and sets the @error flag to non-zero, @extended may contain GPSTATUS error code ($GDIP_ERR* see GPIPlusConstants.au3).
@error: | -1 - GDIPlus.dll does not support this function. 10 - Invalid parameters.

## Remarks

The original pixel data in the bitmap is replaced by the new pixel data.

## Related

_GDIPlus_PaletteInitialize

## See Also

Search GdipBitmapConvertFormat in MSDN Library.

## Example

    #include <GDIPlus.au3>
    #include <GUIConstantsEx.au3>
    #include <MsgBoxConstants.au3>

    _Example()

    Func _Example()
        If Not _GDIPlus_Startup() Or @extended < 6 Then
            MsgBox($MB_SYSTEMMODAL, "ERROR", "GDIPlus.dll v1.1 not available")
            Return
        EndIf

        Local $sFile = FileOpenDialog("Select an image", "", "Images (*.bmp;*.png;*.jpg;*.gif;*.tif)")
        If @error Or Not FileExists($sFile) Then Return

        Local $hImage = _GDIPlus_ImageLoadFromFile($sFile)

        Local $iWidth = 600
        Local $iHeight = _GDIPlus_ImageGetHeight($hImage) * 600 / _GDIPlus_ImageGetWidth($hImage)

        Local $hGui = GUICreate("GDI+ v1.1 (" & @ScriptName & ")", $iWidth, $iHeight)
        Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
        GUISetState(@SW_SHOW)

        ;Convert to a 16-color bitmap (4 bits per pixel) using FixedHalftone27 dithering
        Local $tPalette = _GDIPlus_PaletteInitialize(16, $GDIP_PaletteTypeFixedHalftone27, 16, False, $hImage)
        _GDIPlus_BitmapConvertFormat($hImage, $GDIP_PXF04INDEXED, $GDIP_DitherTypeDualSpiral8x8, $GDIP_PaletteTypeFixedHalftone27, $tPalette)

        _GDIPlus_GraphicsDrawImageRect($hGraphics, $hImage, 0, 0, $iWidth, $iHeight)

        Do
        Until GUIGetMsg() = $GUI_EVENT_CLOSE

        _GDIPlus_ImageDispose($hImage)
        _GDIPlus_GraphicsDispose($hGraphics)
        _GDIPlus_Shutdown()
    EndFunc   ;==>_Example