ImageExtensionsDrawInto(Image, Bitmap, Point, IQuantizer, IDitherer) Method

Draws the source Image into the target Bitmap without scaling. This method is similar to Graphics.DrawImage methods, except that this one always preserves the source size in pixels, works between any pair of source and target PixelFormats and supports quantizing and dithering. For scaling use the overloads with targetRectangle and ScalingMode parameters.

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,
	Point targetLocation = default,
	IQuantizer? quantizer = null,
	IDitherer? ditherer = null
)

Parameters

source  Image
The source Image to be drawn into the target.
target  Bitmap
The target Bitmap into which source should be drawn.
targetLocation  Point  (Optional)
The target location. Target size will be always the same as the source size. This parameter is optional.
Default value: Point.Empty.
quantizer  IQuantizer  (Optional)
An IQuantizer instance to be used for the drawing. If not specified, then the drawing operation might automatically pick a quantizer based on target PixelFormat. This parameter is optional.
Default value: .
ditherer  IDitherer  (Optional)
The ditherer to be used for the drawing. Might be ignored if quantizer is not specified and target PixelFormat format has at least 24 bits-per-pixel size. This parameter is optional.
Default value: .

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 image to be drawn is automatically clipped if its size or targetLocation makes it impossible to completely fit in the target.

If target can represent a narrower set of colors, then the result will be automatically quantized to the colors of the target, even if there is no quantizer specified. To use dithering a ditherer must be explicitly specified though.

If quantizer is specified but it uses more/different colors than target can represent, then the result will eventually be quantized to target, though the result may have a poorer quality than expected.

This overload does not resize the image even if source and target have different DPI resolution.

Exceptions

ArgumentNullExceptionsource or target is .

See Also