这是一个方法  只需要在前面调用就可以额! 

 

public static void DisplayPic()
    {
        string msg = GetRandomString();
        HttpContext.Current.Session["code"] = msg; ;
        Bitmap image = new Bitmap(50, 20);
        Graphics g = Graphics.FromImage(image);
        g.Clear(Color.White);

        Random random = new Random();

        for (int i = 0; i < 20; i++)
        {
            int x1 = random.Next(image.Width);
            int y1 = random.Next(image.Height);
            int x2 = random.Next(image.Width);
            int y2 = random.Next(image.Height);

            g.DrawLine(new Pen(Color.Silver), x1, y1, x2, y2);
        }
        Font font = new Font("宋体", 12);
        SolidBrush brush = new SolidBrush(Color.Blue);
        PointF point = new PointF(2, 2);
        g.DrawString(msg, font, brush, point);

        g.DrawRectangle(new Pen(Color.Silver), 0, 0, image.Width - 1, image.Height - 1);
        MemoryStream ms = new MemoryStream();
        image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
        HttpContext.Current.Response.BinaryWrite(ms.ToArray());
    }

 

 

 

 protected void Page_Load(object sender, EventArgs e)
    {
        Common.DisplayPic();

    }

相关文章:

  • 2021-07-11
  • 2021-10-02
  • 2022-12-23
  • 2021-04-29
  • 2021-11-17
  • 2021-04-05
  • 2021-08-13
  • 2022-01-16
猜你喜欢
  • 2022-01-13
  • 2021-12-03
  • 2021-11-21
  • 2021-11-01
  • 2021-05-06
  • 2022-12-23
  • 2022-02-01
相关资源
相似解决方案