BitmapSourceExtensionsGetReadableBitmapData(BitmapSource, Color, Byte) Method

Gets a managed read-only accessor for a BitmapSource instance.
See the Remarks section of the BitmapExtensions.GetReadWriteBitmapData method for details and code samples. That method is for the GDI+ Bitmap type but the main principles apply for this method, too.

Definition

Namespace: KGySoft.Drawing.Wpf
Assembly: KGySoft.Drawing.Wpf (in KGySoft.Drawing.Wpf.dll) Version: 8.1.0
C#
public static IReadableBitmapData GetReadableBitmapData(
	this BitmapSource bitmap,
	Color backColor = default,
	byte alphaThreshold = 128
)

Parameters

bitmap  BitmapSource
A BitmapSource instance, whose data is about to be accessed.
backColor  Color  (Optional)
For an IReadableBitmapData instance the backColor is relevant only for indexed bitmaps when GetNearestColorIndex and GetNearestColor methods are called with an alpha color on the Palette property. Queried colors with alpha, which are considered opaque will be blended with this color before performing a lookup. The alpha value (Color.A property) of the specified background color is ignored. This parameter is optional.
Default value: The bitwise zero instance of Color, which has the same RGB values as Black.
alphaThreshold  Byte  (Optional)
Similarly to backColor, for an IReadableBitmapData instance the alphaThreshold is relevant only for indexed bitmaps when GetNearestColorIndex and GetNearestColor methods are called with an alpha color on the Palette property. In such case determines the lowest alpha value of a color, which should not be considered as transparent. If 0, then a color lookup will never return a transparent color. This parameter is optional.
Default value: 128.

Return Value

IReadableBitmapData
An IReadableBitmapData instance, which provides fast read-only access to the actual data 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 BitmapSource. 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).

See Also