国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

理解HttpHandler,并為所有*.jpg圖片生成一段文字于圖片上

2024-07-10 12:41:28
字體:
來源:轉載
供稿:網友
接口IHttpHandler的定義如下:
代碼如下:
interface IHttpHandler
{
void ProcessRequest(HttpContext ctx);
bool IsReuseable { get; }

1新建一網站,名為MyHttpHandlerTest
2右擊添加,選擇類庫,取名為MyHttpHandler
3-在上一步新建的類庫上右鍵添加System.Web引用

主要代碼:
代碼如下:
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
}
}

4-在MyHttpHandler類庫上右鍵,生成,取名為MyHttpHandler

5-在web.config中的system.web節點中天下如下節點
<httpHandlers>
<add verb="*" path="Handler1.aspx" type="MyHttpHandler.Class1,MyHttpHandler"/>
<!--
配置文件中的選項說明:

· verb可以是"GET"或"POST",表示對GET或POST的請求進行處理。"*"表示對所有請求進行處理。

· Path指明對相應的文件進行處理,"*.aspx"表示對發給所有ASPX頁面的請求進行處理。可以指明路徑,如"/test/*.aspx",表明只對test目錄下的ASPX文件進行處理。

· Type屬性中,逗號前的字符串指明HttpHandler的實現類的類名,后面的字符串指明Dll文件的名稱。

格式如:type="自定義HttpHandler的實現類的全名,自定義HttpHandler的實現類的命名空間(即Dll名)"

或 type="自定義HttpHandler的實現類的全名"
-->
</httpHandlers>
6-在MyHttpHandlerTest右鍵添加引用,選擇項目找到剛才編譯后的.dll文件

7-運行Handler1.aspx,頁面顯示:

下面我們利用HttpHandler將一段文字生成于圖片中
添加一個類,默認為Class.cs
代碼如下:
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);
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 贵定县| 重庆市| 布拖县| 吴忠市| 福州市| 元氏县| 全南县| 蒙自县| 临安市| 甘肃省| 柘荣县| 丰城市| 应城市| 诸城市| 新田县| 宜州市| 图木舒克市| 徐水县| 阿瓦提县| 广宗县| 仁寿县| 苍山县| 宝山区| 东丰县| 措美县| 略阳县| 兴宁市| 虹口区| 沭阳县| 应城市| 仙居县| 泰州市| 林口县| 永济市| 邓州市| 保定市| 彩票| 灵璧县| 洛浦县| 井陉县| 高安市|