public Restore ( GraphicsState state ) : void | ||
state | GraphicsState | |
return | void |
using System.Drawing; // Create a bitmap and graphics context Bitmap bmp = new Bitmap(100, 100); Graphics g = Graphics.FromImage(bmp); // Save the graphics state g.Save(); // Make some changes to the graphics context g.TranslateTransform(50, 50); g.RotateTransform(45); // Restore the previous graphics state g.Restore(); // Draw a line g.DrawLine(Pens.Black, 0, 0, 100, 100);
using System.Drawing.Drawing2D; // Create a bitmap and graphics context Bitmap bmp = new Bitmap(100, 100); Graphics g = Graphics.FromImage(bmp); // Create a path consisting of several lines and curves GraphicsPath path = new GraphicsPath(); path.AddLine(10, 10, 50, 10); path.AddCurve(new Point[] { new Point(50, 10), new Point(50, 50), new Point(90, 50) }); // Create a linear gradient brush LinearGradientBrush brush = new LinearGradientBrush(new Point(10, 10), new Point(90, 50), Color.Red, Color.Blue); // Save the graphics state g.Save(); // Fill the path with the gradient brush g.FillPath(brush, path); // Restore the previous graphics state g.Restore(); // Draw a line g.DrawLine(Pens.Black, 0, 0, 100, 100);Package/Library: The System.Drawing namespace is part of the .NET Framework and is used to work with graphics-related objects and functions.