BitmapExtensionsGetColorCount Method

Gets the actual number of colors of the specified bitmap. Colors are counted even for indexed bitmaps.

Definition

Namespace: KGySoft.Drawing
Assembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 9.2.0
C#
public static int GetColorCount(
	this Bitmap bitmap
)

Parameters

bitmap  Bitmap
The bitmap, whose colors have to be counted to count its colors.

Return Value

Int32
The actual number of colors of the specified bitmap.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Bitmap. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Remarks

Completely transparent pixels are considered the same regardless of their color information.

Every PixelFormat is supported, but an accurate result is returned for wide color formats only when RowSize is large enough to access all pixels directly (might not be the case for a clipped bitmap data, for example). Otherwise, colors are quantized to 32 bits-per-pixel values while counting them. Wide pixel formats are Format16bppGrayScale, Format48bppRgb, Format64bppArgb and Format64bppPArgb.

See Also