Draw a polygon using PathGradientBrush
DrawPolygonUsingPathGradientBrush.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Text" %>
<%@ Import Namespace="System.Drawing.Drawing2D" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
Bitmap bmp = new Bitmap(600,250);
Graphics g = Graphics.FromImage(bmp);
g.Clear(Color.SeaShell);
GraphicsPath gPath = new GraphicsPath();
Rectangle rect = new Rectangle(0, 0, 600, 250);
gPath.AddRectangle(rect);
PathGradientBrush pathGradientBrush = new PathGradientBrush(gPath);
pathGradientBrush.CenterColor = Color.DarkGreen;
Color[] colors = { Color.LawnGreen };
pathGradientBrush.SurroundColors = colors;
Pen pathGradientPen = new Pen(pathGradientBrush, 20);
Point p1 = new Point(75, 125);
Point p2 = new Point(200, 150);
Point p3 = new Point(175, 175);
Point p4 = new Point(225, 200);
Point p5 = new Point(275, 150);
Point p6 = new Point(250, 150);
Point p7 = new Point(400, 65);
Point[] pointArray = { p1, p2, p3, p4, p5, p6, p7 };
g.DrawPolygon(pathGradientPen, pointArray);
String path = Server.MapPath("~/Image/DrawPolygonUsingPathGradientBrush.jpg");
bmp.Save(path,ImageFormat.Jpeg);
Image1.ImageUrl = "~/Image/DrawPolygonUsingPathGradientBrush.jpg";
g.Dispose();
bmp.Dispose();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>c# 2D Drawing PathGradientBrush - how to draw a polygon</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:MidnightBlue; font-style:italic;">
How to draw a polygon using path gradient brush
<br />System.Drawing.Drawing2D.PathGradientBrush
<br />.NET GDI+ Graphics
</h2>
<hr width="600" align="left" color="DarkBlue" />
<asp:Image
ID="Image1"
runat="server"
/>
<br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Draw A Polygon Using PathGradientBrush"
Height="45"
Font-Bold="true"
ForeColor="DarkBlue"
/>
</div>
</form>
</body>
</html>

- How to use Pen Alignment property Inset
- How to use Pen LineJoin Miter
- Pen LineJoin MiterClipped
- How to create a new bitmap image and draw a line
- How to draw a transparent cardinal spline
- LinearGradientBrush LinearGradientMode Vertical
- How to draw a gradient text
- How to draw a line
- How to fill a transparent rectangle
- How to use PathGradientBrush Blend