ReadableBitmapDataExtensionsToSKBitmap(IReadableBitmapData, SKColorType, SKAlphaType, WorkingColorSpace, IQuantizer, IDitherer) Method

Converts the specified source to an SKBitmap that has the specified colorType, alphaType and color space.

Definition

Namespace: KGySoft.Drawing.SkiaSharp
Assembly: KGySoft.Drawing.SkiaSharp (in KGySoft.Drawing.SkiaSharp.dll) Version: 10.0.0-rc.1
C#
public static SKBitmap ToSKBitmap(
	this IReadableBitmapData source,
	SKColorType colorType,
	SKAlphaType alphaType = SKAlphaType.Unknown,
	WorkingColorSpace targetColorSpace = WorkingColorSpace.Default,
	IQuantizer? quantizer = null,
	IDitherer? ditherer = null
)

Parameters

source  IReadableBitmapData
The source IReadableBitmapData instance to convert.
colorType  SKColorType
Determines the ColorType property of the result SKBitmap. Can be Unknown to auto select a color type that matches the source pixel format.
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 auto select an alpha type that matches the source pixel format. 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 quantizer is . This parameter is optional.
Default value: Default.
quantizer  IQuantizer  (Optional)
An optional IQuantizer instance to determine the colors of the result. This parameter is optional.
Default value: .
ditherer  IDitherer  (Optional)
The ditherer to be used. Might be ignored if quantizer is not specified and colorType represents a higher bits-per-pixel per color channel format. This parameter is optional.
Default value: .

Return Value

SKBitmap
An SKBitmap converted from the specified source.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IReadableBitmapData. 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 ToSKBitmapAsync method for asynchronous call and to adjust parallelization, set up cancellation and for reporting progress.

To produce an SKBitmap with the best matching pixel format to source, use the ToSKBitmap(IReadableBitmapData) overload instead.

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 (unless quantizer is specified, which determines the working color space). To create a result with sRGB color space but perform the conversion in the linear color space either use a quantizer and configure it working in the linear color space, or create an SKBitmap manually, obtain an IWritableBitmapData for it by the GetWritableBitmapData(SKBitmap, WorkingColorSpace, SKColor, Byte) method specifying the Linear working color space, and use the CopyTo(IReadableBitmapData, IWritableBitmapData, Point, IQuantizer, IDitherer) method to copy source into the manually created SKBitmap.

Exceptions

ArgumentNullExceptionsource is .
ArgumentOutOfRangeExceptioncolorType, alphaType or targetColorSpace does not specify a defined value.

See Also