Matrix Transform

Drawing Bitmap

Applies matrix transformation to graphics.

Сode Snippet

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.GetAdvancedGraphics())
{
    // 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");
}

Output

TransformCoordinates.png

For AI-assisted development: Download Graphics Mill Code Samples XML Catalog