using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;//这是在.ashx 中引用session 的必备条件之一
namespace CSDN
{
/// <summary>
/// yzm 的摘要说明
/// </summary>
public class yzm : IHttpHandler, IRequiresSessionState//继承IReadOnlySessionState
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/jpeg";
Random r = new Random();
string s = r.Next(1000, 9999).ToString();
//string path = @"C:\Users\Administrator.PC-20120110JFDT\Documents\Visual Studio 2010\Projects\2013\CSDN\CSDN\img\untitled.bmp";
string path = System.Web.HttpContext.Current.Server.MapPath("~/img/untitled.bmp");//如何使用server.mappath
using (System.Drawing.Bitmap b = new System.Drawing.Bitmap(path))//由图片生成一个bmp的图片
{
using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(b))//生成一个画布,画布上面的图片是刚刚创建的bmp
{
g.DrawString(s, new System.Drawing.Font("宋体", 20), System.Drawing.Brushes.Red, 0, 0);//在画布上写字
}
b.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Bmp);
}
context.Session["yzm"]=s;
}
public bool IsReusable
{
get
{
return false;
}
}
}
}