Created
November 2, 2023 21:30
-
-
Save conholdate-gists/c998359dbbeb99f6ba449e85b745ddee to your computer and use it in GitHub Desktop.
Draw Polygon in C# | Create Polygon Drawing in C# .NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create Bitmap class object | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
// Initialize a Graphics class instance | |
Graphics graphics = Graphics.FromImage(bitmap); | |
// Create a brush while specifying its color | |
Brush brush = new SolidBrush(Color.FromKnownColor(KnownColor.CornflowerBlue)); | |
// Create the filled polygon | |
graphics.FillPolygon(brush, new Point[] { new Point(25, 350), new Point(450, 350), new Point(475, 150), new Point(225, 50), new Point(10, 150) }); | |
// Export the output image | |
bitmap.Save("Filled-Polygon.png"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create Bitmap class object | |
Bitmap bitmap = new Bitmap(1000, 800, System.Drawing.Imaging.PixelFormat.Format32bppPArgb); | |
// Initialize a Graphics class instance | |
Graphics graphics = Graphics.FromImage(bitmap); | |
// Create a Pen class object | |
Pen pen = new Pen(Color.FromKnownColor(KnownColor.Blue), 2); | |
// Draw the polygon shape | |
graphics.DrawPolygon(pen, new Point[] { new Point(100, 100), new Point(500, 700), new Point(900, 300), new Point(650, 100) }); | |
// Export the output image | |
bitmap.Save("Draw-Polygon.png"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment