復制代碼 代碼如下:
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("大蝸牛");
}
新聞熱點
疑難解答
圖片精選