BitmapDataExtensionsResize(IReadableBitmapData, Size, ScalingMode, Boolean, ParallelConfig) Method

Resizes the specified source.

Definition

Namespace: KGySoft.Drawing.Imaging
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 10.0.0-rc.1
C#
public static IReadWriteBitmapData? Resize(
	this IReadableBitmapData source,
	Size newSize,
	ScalingMode scalingMode,
	bool keepAspectRatio,
	ParallelConfig? parallelConfig
)

Parameters

source  IReadableBitmapData
The source IReadableBitmapData to resize.
newSize  Size
The requested new size.
scalingMode  ScalingMode
A ScalingMode value, which determines the quality of the result as well as the processing time.
keepAspectRatio  Boolean
to keep aspect ratio of the specified source; otherwise, .
parallelConfig  ParallelConfig
The configuration of the 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. If , then the degree of parallelization is configured automatically.

Return Value

IReadWriteBitmapData
An IReadWriteBitmapData, which is the resized version of the specified source, or , if the operation was canceled and the ThrowIfCanceled property of the parallelConfig parameter was .

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 blocks the caller as it executes synchronously, though the parallelConfig parameter allows configuring the degree of parallelism, cancellation and progress reporting. Use the BeginResize or ResizeAsync (in .NET Framework 4.0 and above) methods to perform the operation asynchronously.

The result PixelFormat depends on the PixelFormat and WorkingColorSpace of the source bitmap data, but is always at least a 24 BPP format. To resize a bitmap data with a custom pixel format you can create a new IReadWriteBitmapData instance by the CreateBitmapData(Size, KnownPixelFormat, Color32, Byte) method and use the DrawInto extension methods, which have several overloads that allow also quantizing and dithering.

Exceptions

ArgumentNullExceptionsource is .
ArgumentOutOfRangeExceptionnewSize is invalid
-or-
scalingMode has an unsupported value.

See Also