ASP.NET 中的 5 角星坐标

Coordinates For A 5-Pointed Star In ASP.NET

我想做的是画一个五角星。我得到了坐标,但我相信我缺少宽度和高度。我走在正确的轨道上,因为我使用代码测试了程序以输出一个矩形,这非常简单。密码是

g.DrawRectangle(new Pen(Color.Red), 50, 50, 50, 50); 

但是对于一个 5 角星,我只是不知道宽度和高度应该是多少。我将不胜感激任何帮助。 这是:

 <%@ 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>

屏幕截图

您的代码已经可以正常工作了。你只需要使用一个方便的点数组。例如,对于 150x150 位图:

 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();
    }