IHttpHandlerを継承してグローバルピクチャ透かしを実現


変換元:http://www.myexception.cn/asp-dotnet/1589884_2.html
IHttpHandlerを継承してグローバルピクチャ透かしを実現
本帖最后由butterfly_onflyは2014-03-1023:29:51に編集
作成されました
继承IHttpHandler实现全局图片水印_第1张图片
ImageHandlerクラスライブラリ、namespace ImageHandlerを作成
{
    public class WriteHandler:IHttpHandler
    {
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        public void ProcessRequest(HttpContext context)
        {
          
//画像パスの取得
            string imgpath = context.Request.PhysicalPath;
//透かし画像のパス取得
            string wpath = context.Server.MapPath("~/img/logo.jpg");
//デフォルトの画像パスの取得
            string dpath = context.Server.MapPath("~/img/noPicture.jpg");
            Image img;
if(File.Exists)//画像が存在するか否か判断
            {
                img = Image.FromFile(imgpath);//画像をロード
                Image wimg = Image.FromFile(wpath);//透かし画像をロード
                Graphics g = Graphics.FromImage(img);//表示される画像を背景画像に設定
//画像を表示する長方形を描く
                Rectangle re = new Rectangle(img.Width - wimg.Width, img.Height - wimg.Height, wimg.Width, wimg.Height);
//透かし画像の長方形を描く
                Rectangle re1 = new Rectangle(0, 0, wimg.Width, wimg.Height);
                g.DrawImage(wimg, re, re1, GraphicsUnit.Pixel);
//文字透かし
                //LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, wimg.Width, wimg.Height), Color.White, Color.WhiteSmoke, 1.3f, true);
//g.DrawString(「神農蜂語」,new Font(「楷書」,15),brush,img.Width - wimg.Width, img.Height - wimg.Height);
                g.Dispose();
                wimg.Dispose();
            }
            else
            {
                img = Image.FromFile(dpath);//画像が存在しない場合は、デフォルトの画像をロードします.
            }
//保存
            img.Save(context.Response.OutputStream, ImageFormat.Jpeg);
            img.Dispose();
        }
    }
}
WebアプリケーションのWeb.config内の構成
        
      
        
      
    
しかし、ページをブラウズして、エラーを報告しました.
继承IHttpHandler实现全局图片水印_第2张图片
アプリケーションの中でどのようにwebを配置します.config?
---------------------------------------------------------------------------