代码:
- public void ProcessRequest(HttpContext context){context.Response.ContentType = "image/jpeg";//创建位图,并且给指定边框的宽高using (Image img=new Bitmap(80,25)){//创建画家对象,在img对象画字符串using (Graphics g=Graphics.FromImage(img)){ //设置位图的背景颜色,默认是黑色g.Clear(Color.White);//设置验证码的宽高, img.Width-1, img.Height-1主要是背景颜色覆盖了边框线g.DrawRectangle(Pens.Black, 0, 0, img.Width-1, img.Height-1);//传100个噪点,传画家对象,位图对象DrawPoint(100, g, img);//画4个验证码的字符串string vcode=GetCode(4);//vcode这里可以赋值给Cookieg.DrawString(vcode,new Font("Arial", 14, FontStyle.Strikeout | FontStyle.Strikeout), // FontStyle字体的样式,多个样式,需要|线Brushes.Black,new RectangleF(r.Next(20), r.Next(7), img.Width, img.Height));img.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);//保存验证码对象,指定是Jpeg格式}}}//画噪点方法void DrawPoint(int point,Graphics g,Image img){for (int i = 0; i
更多asp.net创建位图生成验证图片类(验证码类)相关文章请关注PHP中文网!
登录后复制
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。