What I'm trying to do is draw a 5 pointed star. I got the coordinates but I believe I'm missing the width and height. I'm on the right track because I tested the program using code to output a rectangle, which was pretty simple. the code was
g.DrawRectangle(new Pen(Color.Red), 50, 50, 50, 50);
But for a 5 pointed star I just don't know what the width and height should be. I'd appreciate any help. Here it is:
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Drawing.Imaging" %>
<script runat="server">
void
Page_Load()
{
Response.ContentType = "image/jpeg";
Response.Clear();
Bitmap bitmap1 = new Bitmap(151, 151);
Graphics g = Graphics.FromImage(bitmap1);
g.Clear(Color.White);
Point[] points = {
new Point(28, 0), new Point(495, 55), new Point(514, 55),
new Point(520,40), new Point(526, 55), new Point(550, 55),
new Point(530, 65), new Point(540,85), new Point(520, 72),
new Point(500, 85), new Point(510, 65), new Point(495,55)};
g.DrawLines(new Pen(Color.Black), points);
bitmap1.Save(Response.OutputStream, ImageFormat.Jpeg);
bitmap1.Dispose();
g.Dispose();
Response.Flush();
}
</script>
Your code already works as it is. You just need to use a convenient array of points. For intance, for a 150x150 bitmap:
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "image/jpeg";
Response.Clear();
Bitmap bitmap1 = new Bitmap(150, 150);
Graphics g = Graphics.FromImage(bitmap1);
g.Clear(Color.White);
Point[] points = {
new Point(75,0),
new Point(150,150),
new Point(0,50),
new Point(150,50),
new Point(0,150),
new Point(75,0)
};
g.DrawLines(Pens.Black, points);
bitmap1.Save(Response.OutputStream, ImageFormat.Jpeg);
bitmap1.Dispose();
g.Dispose();
Response.Flush();
}