BitmapExtensionsClear(Bitmap, Color, Color, Byte) Method

Clears the complete bitmap and fills it with the specified color.
This method is similar to Graphics.Clear but can be used for Bitmaps of any PixelFormat.

Definition

Namespace: KGySoft.Drawing
Assembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 9.2.0
C#
public static void Clear(
	this Bitmap bitmap,
	Color color,
	Color backColor = default,
	byte alphaThreshold = 128
)

Parameters

bitmap  Bitmap
The Bitmap to be cleared.
color  Color
A Color that represents the desired result color of the bitmap.
backColor  Color  (Optional)
If bitmap cannot have alpha or has only single-bit alpha, and color is not fully opaque, then specifies the color of the background. If color has alpha and it is considered opaque, then it will be blended with backColor to determine the color of the cleared bitmap. The Color.A property of the background color is ignored. This parameter is optional.
Default value: Empty, which has the same RGB values as Black.
alphaThreshold  Byte  (Optional)
If bitmap has only single-bit alpha or its palette contains a transparent color, then specifies a threshold value for the Color.A property, under which the specified color is considered transparent. If 0, then the cleared bitmap will not be transparent. This parameter is optional.
Default value: 128.

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

  Note

This method adjusts the degree of parallelization automatically, blocks the caller, and does not support cancellation or reporting progress. Use the BitmapDataExtensions.BeginClear or BitmapDataExtensions.ClearAsync (in .NET Framework 4.0 and above) methods for asynchronous call and to adjust parallelization, set up cancellation and for reporting progress.

See Also