DrawingOptionsTransformation Property

Gets or sets the transformation matrix to apply when drawing shapes.
Default value: TransformationMatrix.Identity.

See the online help for an example with image.

Definition

Namespace: KGySoft.Drawing.Shapes
Assembly: KGySoft.Drawing.Core (in KGySoft.Drawing.Core.dll) Version: 9.0.0
C#
public TransformationMatrix Transformation { get; set; }

Property Value

TransformationMatrix

Remarks

This property allows applying transformations (e.g. translation, rotation, zoom, etc.) when drawing shapes. It can be particularly useful when drawing shapes directly, without creating a Path instance. For example, the DrawEllipse methods don't offer a parameter for rotation.

Setting this property to a value other than the identity matrix disables path region caching for Path instances, even if Path.PreferCaching is . To achieve the best performance when drawing the same shape with the same transformation multiple times, use a Path instance with caching enabled, apply the transformation to the Path, and use the identity matrix here.

Examples

The following example demonstrates how to draw a rotated ellipse directly, without creating a Path instance:
C#
using IReadWriteBitmapData bmp = BitmapDataFactory.CreateBitmapData(100, 100);
bmp.Clear(Color.Cyan);

// Creating a rotation transformation matrix from the center of the ellipse.
var tr = TransformationMatrix.CreateRotationDegrees(45f, new PointF(50f, 50f));
var options = new DrawingOptions { AntiAliasing = true, Transformation = tr };

// Drawing the ellipse with the transformation matrix.
bmp.DrawEllipse(Color.Blue, 0, 25, 100, 50, options);

The example above produces the following result:
Ellipse drawn with a 45 degree rotation

See Also