标题:iis7.0配置映射实现水印效果【IHttpHandler接口】
只看楼主
等待冰柠檬
Rank: 2
来 自:浙江温州
等 级:论坛游民
帖 子:208
专家分:70
注 册:2008-6-25
结帖率:66.67%
 问题点数:0 回复次数:0 
iis7.0配置映射实现水印效果【IHttpHandler接口】
代码:
程序代码:
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环境
搜索更多相关主题的帖子: 映射 效果 接口 IHttpHandler 水印 
2010-09-08 14:00



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-319567-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.379536 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved