如题所说
到底能不能,我现在在网上搜到的代码,只能为一张图片加,而且加得效果也不满意,今天有问过老师说是能批量加,请问各位大虾,如何批量加?

解决方案 »

  1.   

    可以。写一个处理类,如下:using System;
    using System.Web;
    using System.IO;
    using System.Drawing;public class CoverHandler : IHttpHandler
    {
        public CoverHandler() { }
        
        //水印图片
        private const string water_url = @"~/image/WaterMark.jpg";    //默认图片目录
        private string image_url = @"~/image/default.jpg";    public void ProcessRequest(HttpContext context)
        {
            string phypath = context.Request.PhysicalPath;    
            System.Drawing.Image Cover;
            if (File.Exists(phypath))
            {
                //加载当前访问的图片
                Cover = Image.FromFile(phypath);            //加载水印图片
                Image water = Image.FromFile(context.Request.MapPath(water_url));            //实例化画布
                Graphics g = Graphics.FromImage(Cover);
                
                //把水印画在画布上。
                g.DrawImage(water, new Rectangle(Cover.Width - water.Width, Cover.Height - water.Height, water.Width, water.Height), 0, 0, water.Width, water.Height, GraphicsUnit.Pixel);
                
                g.Dispose();
                water.Dispose();
            }
            else
            {
                Cover = Image.FromFile(context.Request.MapPath(image_url));
            }
            context.Response.ContentType = "image/jpeg";
            //将图片保存
            Cover.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            Cover.Dispose();
            context.Response.End();
        }    public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }//然后在web.config中进行配置,将所有对图片的请求都交给CoverHandler类处理。在<system.web>节点中加入以下节点:<!--verb:代表谓词(比如GET、POST、FTP等),*代表所有的请求。
            path:表示所有访问该路径的请求都将交给CoverHandle类进行处理
            type:指定逗号分隔的类/程序组合,-->
        <httpHandlers>
          <add verb="*" path="image/*.jpg" type="CoverHandler"/>
        </httpHandlers>
      

  2.   

    网上很多例子的你可以去搜索一下
    http://zzk.cnblogs.com/s?w=%E6%B0%B4%E5%8D%B0
      

  3.   

    只需要写一个处理类,再在XML中配一下就行了,那样每张图片都会加上的