// Create a Graphics object from a Bitmap Bitmap bmp = new Bitmap(500, 500); Graphics g = Graphics.FromImage(bmp); // Apply a rotation transform g.RotateTransform(45); // Reset the transform g.ResetTransform(); // Draw a line from (100, 100) to (400, 400) g.DrawLine(Pens.Black, 100, 100, 400, 400);
// Create a Graphics object from a control Graphics g = this.CreateGraphics(); // Apply a translation transform g.TranslateTransform(50, 50); // Reset the transform g.ResetTransform(); // Draw a rectangle at (0, 0) g.DrawRectangle(Pens.Black, 0, 0, 100, 100);In this example, we create a graphics object from a control on a form (this). We apply a translation transform to move the origin by (50, 50). We then reset the transform and draw a rectangle at the origin (0, 0). The package library for System.Drawing.Graphics is System.Drawing.