ImageExtensionsConvertPixelFormatAsync(Image, PixelFormat, Color, Color, Byte, TaskConfig) Method

Converts the specified image to a Bitmap of the desired PixelFormat asynchronously.

Definition

Namespace: KGySoft.Drawing
Assembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 8.1.0
C#
public static Task<Bitmap?> ConvertPixelFormatAsync(
	this Image image,
	PixelFormat newPixelFormat,
	Color[]? palette,
	Color backColor = default,
	byte alphaThreshold = 128,
	TaskConfig? asyncConfig = null
)

Parameters

image  Image
The original image 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 or supports only single-bit 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: Empty, which has the same RGB values as Black.
alphaThreshold  Byte  (Optional)
If newPixelFormat can represent only single-bit alpha or 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.
asyncConfig  TaskConfig  (Optional)
The configuration of the asynchronous operation such as parallelization, cancellation, reporting progress, etc. When Progress is set in this parameter, then this library always passes a DrawingOperation instance to the generic methods of the IAsyncProgress interface. This parameter is optional.
Default value: .

Return Value

TaskBitmap
A task that represents the asynchronous operation. Its result is the new Bitmap instance with the desired pixel format, or , if the operation was canceled and the ThrowIfCanceled property of the asyncConfig parameter was .

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Image. 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

Alternatively, you can also use the BeginConvertPixelFormat(Image, PixelFormat, Color, Color, Byte, AsyncConfig) method, which is available on every platform.

This method is not a blocking call even if the MaxDegreeOfParallelism property of the asyncConfig parameter is 1.

See Also