void DrawShapes(Brush brush, PointF location, Size size, Graphics g) { g.SaveTransform(); g.TranslateTransform(location); g.RotateTransform(20); // rectangle g.FillRectangle(brush, new RectangleF(size)); // ellipse g.TranslateTransform(0, size.Height + 20); g.FillEllipse(brush, new RectangleF(size)); // pie g.TranslateTransform(0, size.Height + 20); g.FillPie(brush, new RectangleF(new SizeF(size.Width * 2, size.Height)), 0, 360); // polygon g.TranslateTransform(0, size.Height + 20); var polygon = GetPolygon(); g.FillPolygon(brush, polygon); g.RestoreTransform(); }
void DirectTests(Graphics g) { // test translate/rotate DrawRotatedLines(g, Colors.SkyBlue, rotatedLineCenter, (center, angle) => { g.TranslateTransform(center); g.RotateTransform(angle); g.TranslateTransform(-center); }); // test translate/rotate/scale DrawRotatedLines(g, Colors.Salmon, rotatedLineCenter, (center, angle) => { g.TranslateTransform(center); g.RotateTransform(angle); g.TranslateTransform(-center); g.ScaleTransform(.4f); }); // test rotating arcs DrawRotatedArcs(g, Colors.LightBlue, rotatedLineCenter, (center, angle) => { g.TranslateTransform(center); g.RotateTransform(angle); g.TranslateTransform(-center); }); // test transformed text DrawRotatedText(g, Colors.Lime, rotatedTextCenter, (center, angle) => { g.TranslateTransform(center - 40); g.RotateTransform(angle); g.TranslateTransform(-center + 40); }); // Test image drawing g.SaveTransform(); g.TranslateTransform(imageScaleLocation + image.Size / 2); g.ScaleTransform(1, -1); g.TranslateTransform(-imageScaleLocation - image.Size / 2); g.DrawImage(image, imageScaleLocation); g.TranslateTransform(0, -50); g.TranslateTransform(imageScaleLocation + image.Size / 2); g.ScaleTransform(0.3f); g.TranslateTransform(-imageScaleLocation - image.Size / 2); g.DrawImage(image, imageScaleLocation); g.RestoreTransform(); // test skewing g.SaveTransform(); g.MultiplyTransform(Matrix.FromSkew(20, 20)); var textSize = g.MeasureString(font, "Skewed Text"); g.DrawText(font, Colors.White, new PointF(110, 0), "Skewed Text"); g.DrawLine(Pens.White, 110, textSize.Height + 2, 110 + textSize.Width, textSize.Height + 2); g.RestoreTransform(); // test more drawing operations g.SaveTransform(); g.TranslateTransform(480, 20); g.ScaleTransform(0.4f); g.RotateTransform(90); PixelOffsetSection.Draw(g); g.RestoreTransform(); }