Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created June 26, 2020 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aspose-com-gists/0c035ac54f3ae3fc794e8a7e10c5a85b to your computer and use it in GitHub Desktop.
Save aspose-com-gists/0c035ac54f3ae3fc794e8a7e10c5a85b to your computer and use it in GitHub Desktop.
Create or update images using C#
// Create Bitmap object
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb);
// Create and initialize Graphics
Graphics graphics = Graphics.FromImage(bitmap);
// Create Pen
Pen pen = new Pen(Color.FromKnownColor(KnownColor.Blue), 2);
// Draw arc
graphics.DrawArc(pen, 0, 0, 700, 700, 0, 180);
// Create another Pen
Pen pen1 = new Pen(Color.FromKnownColor(KnownColor.Red), 2);
// Draw ellipse
graphics.DrawEllipse(pen1, 10, 10, 900, 700);
// Save the drawing into desired image format
bitmap.Save(@"drawing.png");
// Initialize Bitmap with the input image
Bitmap bitmap = new Bitmap("input.png");
// Initialize graphics
Graphics graphics = Graphics.FromImage(bitmap);
// Create a Pen
Pen pen = new Pen(Color.FromKnownColor(KnownColor.Orange), 4);
// Draw polygon
graphics.DrawPolygon(pen, new Point[] { new Point(100, 100), new Point(500, 400), new Point(900, 100) });
// Save the drawing into desired image format
bitmap.Save(@"drawing_updated.png");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment