ImageExtensionsDrawInto(Image, Bitmap, Rectangle, Rectangle, IDitherer, ScalingMode) Method

Draws the source Image into the target Bitmap with possible scaling. This method is similar to Graphics.DrawImage methods, except that this one works between any pair of source and target PixelFormats and supports quantizing and dithering.

Definition

Namespace: KGySoft.Drawing
Assembly: KGySoft.Drawing (in KGySoft.Drawing.dll) Version: 8.1.0
C#
public static void DrawInto(
	this Image source,
	Bitmap target,
	Rectangle sourceRectangle,
	Rectangle targetRectangle,
	IDitherer? ditherer,
	ScalingMode scalingMode = ScalingMode.Auto
)

Parameters

source  Image
The source Image to be drawn into the target.
target  Bitmap
The target Bitmap into which source should be drawn.
sourceRectangle  Rectangle
A Rectangle that specifies the portion of the source to be drawn into the target.
targetRectangle  Rectangle
A Rectangle that specifies the location and size of the drawn source.
ditherer  IDitherer
The ditherer to be used for the drawing. Might be ignored if target PixelFormat format has at least 24 bits-per-pixel size.
scalingMode  ScalingMode  (Optional)
Specifies the scaling mode if the bitmap data to be drawn needs to be resized. This parameter is optional.
Default value: Auto.

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

  Note

The method has the best performance if sourceRectangle and targetRectangle have the same size, or when scalingMode is NoScaling.

The image to be drawn is automatically clipped if sourceRectangle or targetRectangle exceed bounds, or scalingMode is NoScaling and sourceRectangle and targetRectangle are different.

If target can represent a narrower set of colors, then the result will be automatically quantized to the colors of the target. To use dithering a ditherer must be explicitly specified.

Exceptions

ArgumentNullExceptionsource or target is .
ArgumentOutOfRangeExceptionscalingMode has an unsupported value.

See Also