Csharp/C Sharp by API/System.Drawing.Drawing2D/Matrix
Matrix.Rotate
using System;
using System.Drawing;
using System.Collections;
using System.ruponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
public class Form1 : System.Windows.Forms.Form {
[STAThread]
static void Main() {
Application.Run(new Form1());
}
protected override void OnPaint(PaintEventArgs e) {
Graphics g = CreateGraphics();
string txt = "HELLO";
float alpha = 45.0f;
int fontSize = 24;
Point center = new Point(90, 20);
FontFamily ff = new FontFamily("Times New Roman");
Font f = new Font(ff, fontSize, FontStyle.Regular);
StringFormat sf = new StringFormat();
sf.FormatFlags = StringFormatFlags.DirectionVertical;
g.DrawString(txt, f, new SolidBrush(Color.Blue), center, sf);
g.TranslateTransform(center.X, center.Y);
g.DrawEllipse(Pens.Magenta, new Rectangle(0, 0, 1, 1));
GraphicsPath gp = new GraphicsPath();
gp.AddString(txt, ff, (int)FontStyle.Bold, fontSize + 4, new Point(0, 0), sf);
Matrix m = new Matrix();
m.Rotate(alpha);
gp.Transform(m);
g.DrawPath(Pens.Red, gp);
g.RotateTransform(-alpha);
g.DrawString(txt, f, new SolidBrush(Color.Black), 0, 0, sf);
gp.Dispose(); g.Dispose(); m.Dispose();
}
}
Matrix.TransformPoints
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
public class Matrix1
{
[STAThread]
static void Main(string[] args)
{
Matrix m = new Matrix();
m.Rotate(90, MatrixOrder.Append);
m.Translate(7, 12, MatrixOrder.Append);
Point[] p = {new Point(20, 45)};
Console.WriteLine(p.GetValue(0).ToString());
m.TransformPoints(p);
Console.WriteLine(p.GetValue(0).ToString());
Console.ReadLine();
}
}
Matrix.Translate
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
public class Matrix1
{
[STAThread]
static void Main(string[] args)
{
Matrix m = new Matrix();
m.Rotate(90, MatrixOrder.Append);
m.Translate(7, 12, MatrixOrder.Append);
Point[] p = {new Point(20, 45)};
Console.WriteLine(p.GetValue(0).ToString());
m.TransformPoints(p);
Console.WriteLine(p.GetValue(0).ToString());
Console.ReadLine();
}
}
new Matrix
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
class MobyDick: Form
{
public static void Main()
{
Application.Run(new MobyDick());
}
public MobyDick()
{
ResizeRedraw = true;
}
protected override void OnPaint(PaintEventArgs pea)
{
DoPage(pea.Graphics, ForeColor,ClientSize.Width, ClientSize.Height);
}
protected void DoPage(Graphics grfx, Color clr, int cx, int cy)
{
grfx.Transform = new Matrix(0.707f, 0.707f, -0.707f, 0.707f, 0, 0);
grfx.DrawString("abc", Font, new SolidBrush(clr),
new Rectangle(0, 0, cx, cy));
}
}