zoukankan      html  css  js  c++  java
  • httphandler生成验证图

    <%@ WebHandler Language="C#" Class="image" %>

    using System;
    using System.Web;
    using System.Drawing;

    public class image : IHttpHandler,System.Web.SessionState.IRequiresSessionState {
        
        
    public void ProcessRequest (HttpContext context) {
            context.Response.ContentType 
    = "text/gif";
            Bitmap b 
    = new Bitmap(20060);
            Graphics g 
    = Graphics.FromImage(b);
            g.FillRectangle(
    new SolidBrush(Color.White), 0020060);
            Font font 
    = new Font(FontFamily.GenericSansSerif, 48, FontStyle.Bold, GraphicsUnit.Pixel);
            Random r 
    = new Random();
            
    string letters = "ABCDEFGHIJKMNPQRSTUVWXYX";
            
    string letter;
            System.Text.StringBuilder s 
    = new System.Text.StringBuilder();
            
    for (int x = 0; x < 5; x++)
            
    {
                letter 
    = letters.Substring(r.Next(0, letters.Length - 1), 1);
                s.Append(letter);
                g.DrawString(letter, font, 
    new SolidBrush(Color.Black), x * 38, r.Next(015));
                
            }


            Pen linePen 
    = new Pen(new SolidBrush(Color.Black), 2);
            
    for (int x = 0; x < 6; x++)
            
    {
                g.DrawLine(linePen, 
    new Point(r.Next(0199), r.Next(059)), new Point(r.Next(0199), r.Next(059)));
            }

            b.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
            context.Session[
    "aaa"= s.ToString();
            context.Response.End();
        }


        
    public bool IsReusable
        
    {
            
    get {
                
    return false;
            }

        }

    }
    <img src="image.ashx" />
  • 相关阅读:
    【English】20190522
    06_Intent和IntentFilter
    05_Content Provider
    04_ Broadcast Receiver
    03_Service的绑定
    02_启动和销毁Service
    01_Activity生命周期及传递数据
    Android对应版本号
    如何在word中插入代码
    项目经验总结
  • 原文地址:https://www.cnblogs.com/zwl12549/p/964728.html
Copyright © 2011-2022 走看看