SKBitmapExtensionsConvertPixelFormat(SKBitmap, SKColorType, SKAlphaType, WorkingColorSpace, SKColor, Byte) Method
Converts the pixel format of this bitmap using the specified colorType, alphaType and targetColorSpace.
Namespace: KGySoft.Drawing.SkiaSharpAssembly: KGySoft.Drawing.SkiaSharp (in KGySoft.Drawing.SkiaSharp.dll) Version: 9.0.0
public static SKBitmap ConvertPixelFormat(
this SKBitmap bitmap,
SKColorType colorType,
SKAlphaType alphaType = SKAlphaType.Unknown,
WorkingColorSpace targetColorSpace = WorkingColorSpace.Default,
SKColor backColor = default,
byte alphaThreshold = 128
)
<ExtensionAttribute>
Public Shared Function ConvertPixelFormat (
bitmap As SKBitmap,
colorType As SKColorType,
Optional alphaType As SKAlphaType = SKAlphaType.Unknown,
Optional targetColorSpace As WorkingColorSpace = WorkingColorSpace.Default,
Optional backColor As SKColor = Nothing,
Optional alphaThreshold As Byte = 128
) As SKBitmap
public:
[ExtensionAttribute]
static SKBitmap^ ConvertPixelFormat(
SKBitmap^ bitmap,
SKColorType colorType,
SKAlphaType alphaType = SKAlphaType::Unknown,
WorkingColorSpace targetColorSpace = WorkingColorSpace::Default,
SKColor backColor = SKColor(),
unsigned char alphaThreshold = 128
)
[<ExtensionAttribute>]
static member ConvertPixelFormat :
bitmap : SKBitmap *
colorType : SKColorType *
?alphaType : SKAlphaType *
?targetColorSpace : WorkingColorSpace *
?backColor : SKColor *
?alphaThreshold : byte
(* Defaults:
let _alphaType = defaultArg alphaType SKAlphaType.Unknown
let _targetColorSpace = defaultArg targetColorSpace WorkingColorSpace.Default
let _backColor = defaultArg backColor new SKColor()
let _alphaThreshold = defaultArg alphaThreshold 128
*)
-> SKBitmap
- bitmap SKBitmap
- The original bitmap to convert.
- colorType SKColorType
- Determines the ColorType property of the result SKBitmap.
Can be Unknown to use the original color type of the source bitmap.
- alphaType SKAlphaType (Optional)
- Determines the AlphaType property of the result SKBitmap.
It might be ignored if the colorType cannot have the specified alpha type.
Can be Unknown to use the original alpha type of the source bitmap. This parameter is optional.
Default value: Unknown. - targetColorSpace WorkingColorSpace (Optional)
- Determines both the ColorSpace property of the result SKBitmap,
and also the working color space if the result does not support transparency and source pixels needed to be blended with backColor.
Can be Default to preserve the original color space. This parameter is optional.
Default value: Default. - backColor SKColor (Optional)
- If the result 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 Alpha property of the background color is ignored. This parameter is optional.
Default value: The bitwise zero instance of SKColor, which has the same RGB values as Black. - alphaThreshold Byte (Optional)
- If the result supports alpha, then specifies a threshold value for the Alpha property, under which
the color is considered completely transparent. If 0, then the converted colors attempt to preserve their original alpha value. This parameter is optional.
Default value: 128.
SKBitmapA new
SKBitmap instance with the desired parameters.In Visual Basic and C#, you can call this method as an instance method on any object of type
SKBitmap. 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 ConvertPixelFormatAsync(SKBitmap, SKColorType, SKAlphaType, WorkingColorSpace, SKColor, Byte, TaskConfig) method for asynchronous call
and to adjust parallelization, set up cancellation and for reporting progress.
- The targetColorSpace parameter is purposely not an SKColorSpace value because only sRGB and linear color spaces are supported directly.
If its value is Linear, then both the actual color space of the result and the working color space of the conversion operation will be in
the linear color space. To create a result with sRGB color space but perform the conversion in the linear color space use
the ConvertPixelFormat(SKBitmap, IQuantizer, IDitherer, SKColorType, SKAlphaType, WorkingColorSpace) overload with an IQuantizer
configured to work in the linear color space.
If the result SKBitmap can represent fewer colors than the source bitmap, then a default
quantization will occur during the conversion. To use a specific quantizer (and optionally a ditherer) use the ConvertPixelFormat(SKBitmap, IQuantizer, IDitherer, SKColorType, SKAlphaType, WorkingColorSpace) overload.
To use a quantizer with a specific palette you can use the PredefinedColorsQuantizer class.
The method may produce the following results:
Original image | Quantized image |
---|
Color hues with alpha gradient
| colorType = Argb4444, alphaType = Unpremul, targetColorSpace = Srgb, the other parameters have their default value.
colorType = Rgb565, targetColorSpace = Srgb, the other parameters have their default value.
colorType = Rgb565, targetColorSpace = Linear, the other parameters have their default value.
|