复制代码 代码如下:
interface IHttpHandler
{
void ProcessRequest(HttpContext ctx);
bool IsReuseable { get; }
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.SessionState;
namespace MyHttpHandler
{
public class Class1:IHttpHandler,IRequiresSessionState
{
#region IHttpHandler成员
public bool IsReusable
{
get { return true; }
}
public void ProcessRequest(HttpContext context)
{
context.Response.Write("handler处理");
}
#endregion
}
}
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.SessionState;
using System.Drawing;
/// <summary>
/// Class1 的摘要说明
/// </summary>
public class Class1:IHttpHandler
{
public Class1()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public bool IsReusable
{
get { return true; }
}
private static Image OldImage = null;
private static Image GetOldImage(HttpContext context)
{
if (OldImage == null)
{
OldImage = Image.FromFile(context.Server.MapPath("~/Images/Old.jpg"));
}
return OldImage.Clone() as Image;
}
public void ProcessRequest(HttpContext context)
{
Image newimage = GetOldImage(context);
Graphics gh = Graphics.FromImage(newimage);
Font font = new Font("Monaco", 24.0f, FontStyle.Regular);
string writetext = HttpUtility.UrlEncode(context.Request.QueryString["writetext"]);
gh.DrawString(HttpUtility.UrlDecode(writetext), font, new SolidBrush(Color.LightBlue), 20.0f, newimage.Height - font.Height - 30);
newimage.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
gh.Dispose();
newimage.Dispose();
}
}
复制代码 代码如下:
protected void Page_Load(object sender, EventArgs e)
{
HyperLink1.NavigateUrl = "img.jpg?writetext=" + HttpUtility.UrlEncode("大蜗牛");
}
新闻热点
疑难解答
图片精选