• 验证码


    aspx页面验证码应用的常见处理方式

    <%@ WebHandler Language="C#" Class="resImg" Debug="true"%>
    
    using System;
    using System.Web;
    using System.Drawing;
    
    public class resImg : IHttpHandler,System.Web.SessionState.IRequiresSessionState {//注意此处要实现 IRequireSessionState接口 要不然不能访问session
    
        public void ProcessRequest(HttpContext context)
        {
            context.Response.Clear();
            context.Response.ContentType = "image/jpeg";
    
            //从文件载入一个图像
            //Image img = Image.FromFile(context.Server.MapPath(@"blue hills.jpg")); 
            //Bitmap bmp = new Bitmap(img);
            //bmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
    
            /*
             * 记得以前看C++ GDI绘图的时候讲过什么跟设备有关 跟设备无关
             * 可能这里意思就是说Bitmap跟设备有关,Graphics跟设备无关
             * 总之步骤就是:
             * 1创建一个Bitmap对象 并指定长宽
             * 2然后把一个Graphics往Bitmap对象上套,因为FromImage()里需要Image对象 而Bitmap继承自Image
             * 3然后用这个Graphics去绘图 其实 就是在先前创建的那个Bitmap对象 的“画布”上绘图
             * 4最后输出,依然使用Bitmap
             * 5收工
             */
    
            context.Session["valiCode"] = "hello"; 
            Bitmap bmp = new Bitmap(100, 100);
            Graphics graph = Graphics.FromImage(bmp);//graphics Bitmap继承自Image
            graph.DrawString("hello", new Font("宋体", 25), System.Drawing.Brushes.Red, new PointF(1, 1));
            bmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }
    
    }
    
  • 相关阅读:
    PyQt5 控件学习(一个一个学习之QCommandLinkButton)
    多任务--线程
    PyQt5 控件学习(一个一个学习之QPushButton)
    PyQt5 控件学习(一个一个学习之QAbstractButton)
    再测我心中的事
    花了两天时间,整理了代码,封装了逻辑
    我现在发现,我写代码有严重的问题
    2014年8月2日0时13分22秒
    2014年8月2日15时13分4秒
    交警与货车司机
  • 原文地址:https://www.cnblogs.com/assassinx/p/1811728.html
Copyright © 2020-2023  润新知