Modifier

Partager via


Bitmap.ConvertFormat Method

Definition

Overloads

ConvertFormat(PixelFormat)

Converts the bitmap to the specified format. The original pixel data is replaced with the new format.

ConvertFormat(PixelFormat, DitherType, PaletteType, ColorPalette, Single)

Converts the bitmap to the specified format using the given ditherType. The original pixel data is replaced with the new format.

ConvertFormat(PixelFormat)

Source:
Bitmap.cs
Source:
Bitmap.cs

Converts the bitmap to the specified format. The original pixel data is replaced with the new format.

public:
 void ConvertFormat(System::Drawing::Imaging::PixelFormat format);
public void ConvertFormat (System.Drawing.Imaging.PixelFormat format);
member this.ConvertFormat : System.Drawing.Imaging.PixelFormat -> unit
Public Sub ConvertFormat (format As PixelFormat)

Parameters

format
PixelFormat

The new pixel format.

Remarks

For format, Format16bppGrayScale is not supported.

Applies to

ConvertFormat(PixelFormat, DitherType, PaletteType, ColorPalette, Single)

Source:
Bitmap.cs
Source:
Bitmap.cs

Converts the bitmap to the specified format using the given ditherType. The original pixel data is replaced with the new format.

public void ConvertFormat (System.Drawing.Imaging.PixelFormat format, System.Drawing.Imaging.DitherType ditherType, System.Drawing.Imaging.PaletteType paletteType = System.Drawing.Imaging.PaletteType.Custom, System.Drawing.Imaging.ColorPalette? palette = default, float alphaThresholdPercent = 0);
member this.ConvertFormat : System.Drawing.Imaging.PixelFormat * System.Drawing.Imaging.DitherType * System.Drawing.Imaging.PaletteType * System.Drawing.Imaging.ColorPalette * single -> unit
Public Sub ConvertFormat (format As PixelFormat, ditherType As DitherType, Optional paletteType As PaletteType = System.Drawing.Imaging.PaletteType.Custom, Optional palette As ColorPalette = Nothing, Optional alphaThresholdPercent As Single = 0)

Parameters

format
PixelFormat

The new pixel format.

ditherType
DitherType

The dithering algorithm.

paletteType
PaletteType

The palette type to use when the pixel format is indexed.

palette
ColorPalette

Pointer to a ColorPalette that specifies the palette whose indexes are stored in the pixel data of the converted bitmap. This must be specified for indexed pixel formats.

alphaThresholdPercent
Single

A real number in the range 0 through 100 that specifies which pixels in the source bitmap will map to the transparent color in the converted bitmap.

Remarks

For format, Format16bppGrayScale is not supported.

For ditherType, pass None when the conversion does not reduce the bit depth of the pixel data. This must be Solid or ErrorDiffusion if the paletteType is Custom or FixedBlackAndWhite.

paletteType is ignored for non-indexed pixel formats.

The palette (called the actual palette) does not have to have the type specified by the paletteType parameter. The paletteType parameter specifies a standard palette that can be used by any of the ordered or spiral dithering algorithms. If the actual palette has a type other than that specified by the paletteType parameter, then ConvertFormat(PixelFormat, DitherType, PaletteType, ColorPalette, Single) performs a nearest-color conversion from the standard palette to the actual palette.

For alphaThresholdPercent, a value of 0 specifies that none of the source pixels map to the transparent color. A value of 100 specifies that any pixel that is not fully opaque will map to the transparent color. A value of t specifies that any source pixel less than t percent of fully opaque will map to the transparent color. Note that for the alpha threshold to be effective, the palette must have a transparent color. If the palette does not have a transparent color, pixels with alpha values below the threshold will map to color that most closely matches (0, 0, 0, 0), usually black.

paletteType and palette really only have relevance with indexed pixel formats. You can pass a ColorPalette for non-indexed pixel formats, but it has no impact on the transformation and will effective just call Palette to set the palette when the conversion is complete.

Applies to