---
title: "Matrix Transform"
canonical: https://www.graphicsmill.com/samples/Drawing/Transform/MatrixTransform_cs
product: "Graphics Mill"
source: "Drawing/Transform/MatrixTransform.cs"
---

# Matrix Transform

Applies matrix transformation to graphics.

## Instruction

Draw an ellipse and text with transformations (move, shear, rotate) applied to the coordinate system.

## Usings

```csharp
using Aurigma.GraphicsMill.Drawing;
```

## Code Snippet

```csharp
var drawEllipseAndText = (Graphics graphics) =>
{
    graphics.DrawEllipse(new Pen(new RgbColor(0x01, 0x97, 0xfd), 20f), -280, -135, 560, 270);

    var text = new PlainText("Graphics Mill", graphics.CreateFont("Arial", "Bold", 80f));
    text.Alignment = TextAlignment.Center;
    text.Position = new System.Drawing.PointF(0f, text.GetBlackBox(graphics.FontRegistry, graphics.DpiX, graphics.DpiY).Height / 2);
    text.Brush = new SolidBrush(new RgbColor(0xd4, 0x00, 0x00));

    graphics.DrawText(text);
};

using (var bitmap = new Bitmap(600, 300, PixelFormat.Format24bppRgb, RgbColor.White))
using (var graphics = bitmap.GetGraphics())
{
    // Move coordinate system
    graphics.Transform = new System.Drawing.Drawing2D.Matrix();
    graphics.Transform.Translate(bitmap.Width / 2, bitmap.Height / 2);

    drawEllipseAndText(graphics);

    // Move, shear and rotate coordinate system
    graphics.Transform = new System.Drawing.Drawing2D.Matrix();
    graphics.Transform.Translate(bitmap.Width / 2, bitmap.Height / 2);
    graphics.Transform.Shear(0.5f, 0.1f);
    graphics.Transform.Rotate(30f);

    graphics.Opacity = 0.3f;

    drawEllipseAndText(graphics);

    bitmap.Save("TransformCoordinates.png");
}
```

## Explanation

The code:

- Draws an ellipse and centered text in a normal coordinate system.
- Applies a transformation to the coordinate system (translation to the center) and draws the first shape.
- Then, applies further transformations (translation, shear, rotation) and draws the same shape with altered transformations and reduced opacity.
- Saves the final image to an output file.

## Tags

- [Bitmap](<https://www.graphicsmill.com/samples/tags/bitmap_md>): Working with images via the Bitmap API
- [Drawing](<https://www.graphicsmill.com/samples/tags/drawing_md>): Drawing vector shapes and text

## Output

- [TransformCoordinates.png](<https://www.graphicsmill.com/samples/Drawing/compiled/Debug/TransformCoordinates_png>) (preview)

## Used APIs

- [Aurigma.GraphicsMill.Bitmap.GetGraphics](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Bitmap_GetGraphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Graphics.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.CreateFont(String,String,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_CreateFont_3_2557116e.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DpiX](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_DpiX.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DpiY](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_DpiY.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawEllipse(Pen,Single,Single,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawEllipse_5_b3708ac1.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.DrawText(Text)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Graphics_DrawText_1_f576d03f.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.FontRegistry](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_FontRegistry.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.Opacity](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_Opacity.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Graphics.Transform](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Graphics_Transform.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Pen](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_Pen.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_PlainText.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText.Alignment](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_PlainText_Alignment.htm.md>)
- [Aurigma.GraphicsMill.Drawing.PlainText.Position](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_PlainText_Position.htm.md>)
- [Aurigma.GraphicsMill.Drawing.SolidBrush](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_SolidBrush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.Brush](<https://www.graphicsmill.com/docs/gm/P_Aurigma_GraphicsMill_Drawing_Text_Brush.htm.md>)
- [Aurigma.GraphicsMill.Drawing.Text.GetBlackBox(FontRegistry,Single,Single)](<https://www.graphicsmill.com/docs/gm/M_Aurigma_GraphicsMill_Drawing_Text_GetBlackBox_3_185e8a92.htm.md>)
- [Aurigma.GraphicsMill.Drawing.TextAlignment](<https://www.graphicsmill.com/docs/gm/T_Aurigma_GraphicsMill_Drawing_TextAlignment.htm.md>)
