C#.net验证码问题

 

使用了无效参数。
说明: 执行当前 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();
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值