注册 登录
编程论坛 ASP.NET技术论坛

iis7.0配置映射实现水印效果【IHttpHandler接口】

等待冰柠檬 发布于 2010-09-08 14:00, 973 次点击
代码:
程序代码:
using System;
using System.Collections.Generic;
using System.Web;
using using System.Drawing;
using System.Drawing.Imaging;

/// <summary>
///水印的摘要说明
/// </summary>
public class ShuiYin:IHttpHandler
{
    public ShuiYin()
    {
        //
        
//TODO: 在此处添加构造函数逻辑
        
//
    }

    public bool IsReusable
    {
        get { return true; }
       // get { throw new NotImplementedException(); }
    }

    public void ProcessRequest(HttpContext context)
    {
        string imageFile = context.Request.PhysicalPath;
        Image image = null;
        if (File.Exists(imageFile))
        {
            string text = "本图片来自朝辉电脑";
            Font font = new Font("宋体", 12);
            image = Image.FromFile(imageFile);
            Graphics g = Graphics.FromImage(image);
            SizeF size = g.MeasureString(text, font);
            if (size.Width > image.Width || size.Height > image.Height)
            {
                context.Response.Write("文字太大了");
            }
            else
            {
                Brush brush = Brushes.Blue;
                g.DrawString(text, font, brush, image.Width - size.Width, image.Height - size.Height);
            }
        }
        else
        {
            imageFile = context.Server.MapPath("018.jpg");
            image = Image.FromFile(imageFile);
        }
        image.Save(context.Response.OutputStream, ImageFormat.Jpeg);
        //throw new NotImplementedException();
    }
}

目录:红色圈起来的
只有本站会员才能查看附件,请 登录


说明:直接在vs里面运行的时候可以实现,但是在iis下就不能,但是知道要配置映射,可以试了还是不可以,希望高手帮忙下 iis7.0环境
0 回复
1