C#.net验证码问题

来源:互联网 发布:卖数据是啥 编辑:程序博客网 时间:2024/06/05 00:41

 

使用了无效参数。
说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.ArgumentException: 使用了无效参数。
{"Parameter is not valid."}

源文件: public partial class ValidateImage : System.Web.UI.Page
{
    private readonly string ImagePath = "~/Images/validator.jpg";
    private string sValidator = "";
    private Brush[] BrushList = new Brush[32];

    private void Page_Load(object sender, System.EventArgs e)
    {
        ///初始化
        InitBrushList();

        if (Request.Params["Validator"] != null)
        {
            ///获取验证字符串
            sValidator = Request.Params["Validator"].ToString();
        }

        ///创建Bmp位图
      Bitmap bitMapImage = new System.Drawing.Bitmap(Server.MapPath(ImagePath));
        Graphics graphicImage = Graphics.FromImage(bitMapImage);


        ///设置画笔的输出模式
        graphicImage.SmoothingMode = SmoothingMode.AntiAlias;
        ///添加文本字符串
        for (int i = 0; i < sValidator.Length; i++)
        {
            graphicImage.DrawString(sValidator[i].ToString(),
                new Font("Arial", 20, (FontStyle)CreateRandomFontStyle(GetRandomint(0, 1000))),
                BrushList[GetRandomint(0, BrushList.Length - 1)],
                new PointF(i * 15, GetRandomint(-5, 5)));
        }

        //graphicImage.DrawString(sValidator, new Font("Arial", 20, (FontStyle)GetRandomint(0,4)),SystemBrushes.WindowText, new Point(0, 0));

        ///设置图像输出的格式
        Response.ContentType = "image/jpeg";

        ///保存数据流
        bitMapImage.Save(Response.OutputStream, ImageFormat.Jpeg);

        ///释放占用的资源
        graphicImage.Dispose();
        bitMapImage.Dispose();
        Response.End();
    }