要求提供一个矩形,然后画出五角星,十个点的,可以填充的

解决方案 »

  1.   

    using System.Drawing.Imaging;
    public class _A : System.Web.UI.Page
    {
    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    Point[] pt=new Point[11];
    pt[0]=new Point(0,12);
    pt[1]=new Point(12,12);
    pt[2]=new Point(16,0);
    pt[3]=new Point(20,12);
    pt[4]=new Point(32,12);
    pt[5]=new Point(24,20);
    pt[6]=new Point(26,32);
    pt[7]=new Point(16,24);
    pt[8]=new Point(6,32);
    pt[9]=new Point(10,20);
    pt[10]=new Point(0,12);
    Bitmap bm=new Bitmap(75,75,PixelFormat.Format32bppArgb);
    SChart chart=new SChart(bm,pt);
    bm.Save("c:\\inetpub\\wwwroot\\test\\images\\chart.gif",ImageFormat.Gif);
    //图片保存在能写的一个目录下;
    }
    }
    //
    public class SChart
    {
    public SChart(Bitmap bm,Point[] pt)
    {
    System.Drawing.Graphics g= Graphics.FromImage(bm);
    Drawlines(g,pt);
    }protected void Drawlines(System.Drawing.Graphics g,Point[] pt)
    {
    System.Drawing.SolidBrush b=new SolidBrush(Color.White);//新建画布清空
    g.FillRectangle(b,0,0,75,75);//画图片区域
    System.Drawing.Pen pen=new Pen(Color.Black);
    g.DrawLines(pen,pt);//画线,楼主,你慢慢改成画区域的
    }
    }
      

  2.   

    http://www.codeproject.com/cs/miscctrl/cs_star_rating_control.asp
      

  3.   

    private void DrawStar(Graphics g, int center_x, int center_y, int inner_radius, int outer_radius, int number_of_arms, Color fillColor, Color outlineColor)
            {
                Brush fillBrush;
                Pen outlinePen = new Pen(outlineColor);
                fillBrush = new SolidBrush(fillColor);
        
                PointF[] p = new PointF[number_of_arms*2];            for (int i=0; i<number_of_arms; i++)
                {
                    p[i*2].X = center_x + (float)Math.Cos(i*2*Math.PI/number_of_arms) * outer_radius;
                    p[i*2].Y = center_y + (float)Math.Sin(i*2*Math.PI/number_of_arms) * outer_radius;
                }            for (int i=0; i<number_of_arms; i++)
                {
                    p[i*2+1].X = center_x + (float)Math.Cos(i*2*Math.PI/number_of_arms + 2*Math.PI/(2*number_of_arms)) * inner_radius;
                    p[i*2+1].Y = center_y + (float)Math.Sin(i*2*Math.PI/number_of_arms + 2*Math.PI/(2*number_of_arms)) * inner_radius;
                }                    g.FillPolygon(fillBrush, p);
                g.DrawPolygon(outlinePen, p);
            }for example: 
    DrawStar(g, 100, 100, 12, 30, 5, Color.Yellow, Color.Orange);