BitmapSourceExtensionsConvertPixelFormat(BitmapSource, PixelFormat, Color, Color, Byte) Method
Namespace: KGySoft.Drawing.WpfAssembly: KGySoft.Drawing.Wpf (in KGySoft.Drawing.Wpf.dll) Version: 10.0.0-rc.1
public static WriteableBitmap ConvertPixelFormat(
this BitmapSource bitmap,
PixelFormat newPixelFormat,
Color[]? palette,
Color backColor = default,
byte alphaThreshold = 128
)
<ExtensionAttribute>
Public Shared Function ConvertPixelFormat (
bitmap As BitmapSource,
newPixelFormat As PixelFormat,
palette As Color(),
Optional backColor As Color = Nothing,
Optional alphaThreshold As Byte = 128
) As WriteableBitmap
public:
[ExtensionAttribute]
static WriteableBitmap^ ConvertPixelFormat(
BitmapSource^ bitmap,
PixelFormat newPixelFormat,
array<Color>^ palette,
Color backColor = Color(),
unsigned char alphaThreshold = 128
)
[<ExtensionAttribute>]
static member ConvertPixelFormat :
bitmap : BitmapSource *
newPixelFormat : PixelFormat *
palette : Color[] *
?backColor : Color *
?alphaThreshold : byte
(* Defaults:
let _backColor = defaultArg backColor new Color()
let _alphaThreshold = defaultArg alphaThreshold 128
*)
-> WriteableBitmap
- bitmap BitmapSource
- The original bitmap to convert.
- newPixelFormat PixelFormat
- The desired new pixel format.
- palette Color
- The desired target palette if newPixelFormat is an indexed format. If ,
then the source palette is taken from the source image if it also has a palette of no more entries than the target indexed format can have;
otherwise, a default palette will be used based on newPixelFormat.
- backColor Color (Optional)
- If newPixelFormat does not support alpha, then specifies the color of the background.
Source pixels with alpha, which will be opaque in the result will be blended with this color.
The Color.A property of the 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)
- If newPixelFormat is an indexed format and the target palette contains a transparent color,
then specifies a threshold value for the Color.A property, under which the color is considered transparent. If 0,
then the result will not have transparent pixels. This parameter is optional.
Default value: 128.
WriteableBitmapA new
WriteableBitmap instance with the desired pixel format.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).
- This method adjusts the degree of parallelization automatically, blocks the caller, and does not support cancellation or reporting progress. Use the BeginConvertPixelFormat(BitmapSource, PixelFormat, Color, Color, Byte, AsyncConfig)
or ConvertPixelFormatAsync(BitmapSource, PixelFormat, Color, Color, Byte, TaskConfig) (in .NET Framework 4.0 and above) methods for asynchronous call and to adjust parallelization, set up cancellation and for reporting progress.
- If newPixelFormat requires blending with backColor, then this method selects the working color space automatically.
To apply a specific color space use the GetReadableBitmapData(BitmapSource, WorkingColorSpace, Color, Byte) on a BitmapSource instance,
and then call the ToWriteableBitmap extension method.
If newPixelFormat can represent fewer colors than the source format, then a default
quantization will occur during the conversion. To use a specific quantizer (and optionally a ditherer) use the ConvertPixelFormat(BitmapSource, PixelFormat, IQuantizer, IDitherer) overload.
To use a quantizer with a specific palette you can use the PredefinedColorsQuantizer class.
If newPixelFormat is Indexed8, bitmap has no palette and palette is , then a default 256 color palette will be used containing
the 16 standard basic sRGB colors, the "web-safe" palette of 216 colors as well as 24 transparent entries.
If newPixelFormat is Indexed4, bitmap has no palette and palette is ,
then the 16 standard basic sRGB colors will be used.
If newPixelFormat is Indexed2, bitmap has no palette and palette is , then
the palette will consist of 4 grayscale colors, containing black, white and the two gray entries that present in the default 4-bit palette.
If newPixelFormat is Indexed1, bitmap has no palette and palette is , then black and white colors will be used.