public RotateAt ( float angle, PointF point ) : void | ||
angle | float | |
point | PointF | |
return | void |
using System.Drawing; using System.Drawing.Drawing2D; // Load the image from file Image image = Image.FromFile("image.jpg"); // Create a matrix with a 45 degree rotation around the center of the image Matrix matrix = new Matrix(); matrix.RotateAt(45, new Point(image.Width / 2, image.Height / 2)); // Draw the rotated image using (Graphics g = Graphics.FromImage(image)) { g.Transform = matrix; g.DrawImage(image, 0, 0); }
using System.Drawing; using System.Drawing.Drawing2D; Rectangle rect = new Rectangle(10, 10, 100, 50); Matrix matrix = new Matrix(); matrix.RotateAt(30, new Point(rect.X + rect.Width / 2, rect.Y + rect.Height / 2)); GraphicsPath path = new GraphicsPath(); path.AddRectangle(rect); path.Transform(matrix);This code creates a rectangle, creates a matrix with a 30 degree rotation around the center of the rectangle, and then applies the matrix transformation to a GraphicsPath. The GraphicsPath is then ready to be drawn with the rotated rectangle. The package library for the System.Drawing.Drawing2D namespace is System.Drawing.dll, which is included in the .NET Framework.