在ASP.NET中协调一个五角星

时间:2016-05-21 21:31:34

标签: c# asp.net system.drawing

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

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>

截屏image

1 个答案:

答案 0 :(得分:1)

您的代码已按原样运行。您只需要使用方便的点阵列。对于intance,对于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();
    }

enter image description here