我初学asp.net,诚望告之图片验证码在asp.net如何使用?
请高手赐代码!!!

解决方案 »

  1.   

    http://www.lemongtree.com/zh-cn/search.%e9%aa%8c%e8%af%81%e7%a0%81.aspx
      

  2.   

    private void CreateImage(string vCode)
        {
                    System.Drawing.Bitmap img = new Bitmap(55, 20);        Graphics g = Graphics.FromImage(img);        g.FillRectangle(new SolidBrush(Color.White), 0, 0, 55, 20);        Random random = new Random();        for (int i = 0; i < 40; i = i + 8)
            {
                int r = random.Next(i + 8, i + 16);
                Pen blackPen = new Pen(Color.Silver, 1);
                int x = (img.Width - r) / 2;
                int y = (img.Height - r) / 2;            g.DrawArc(blackPen, x, y, r, r, 0, 360);
            }        int n = 0;
            int w = 0;
            string wStr = "W,M,Q";
            int px = 0;        for (int ii = 0; ii < vCode.Length; ii++)
            {
                string str = vCode.Substring(ii, 1);            Font font = new Font("arial", 13, FontStyle.Bold);            if (n == 1)
                {
                    px -= 2;
                }
                else if (w == 1)
                {
                    px += 4;
                }            if (this.IsNum(str))
                {
                    g.TranslateTransform(px, 3);
                    n = 1;
                }
                else
                {
                    n = 0;
                    if (wStr.IndexOf(str) != -1)
                    {
                        w = 1;
                    }
                    else
                    {
                        w = 0;
                    }
                    g.TranslateTransform(px, 0);            }            px = px + 12;            int degrees = GetDegrees(random);
                g.RotateTransform(degrees);            System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, 13, 13), Color.DarkRed, Color.Black, 1.2f, true);
                g.DrawString(str, font, brush, 0, 0);
                g.ResetTransform();        }
            for (int i = 0; i < 120; i++)
            {
                int x = random.Next(img.Width);
                int y = random.Next(img.Height);            img.SetPixel(x, y, Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)));
            }
            MemoryStream ms = new MemoryStream();
            img.Save(ms, ImageFormat.Png);        Response.ClearContent();
            Response.ContentType = "image/gif";
            Response.BinaryWrite(ms.ToArray());
            g.Dispose();
            img.Dispose();        Response.End();
        }