数字水印

<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.Drawing;
using System.IO;

public class Handler : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
   context.Request.ContentType = "IMAGE/JPEG";
   
   //原始图片的路径,并转换为物理路径
   string path = context.Request.MapPath("~/images/0 (8).jpg");

   //原始图片实例
   Image  img= Image.FromFile(path);
     
   //需要加的水印图片
   Image waterImg = Image.FromFile(context.Request.MapPath("~/images/1 (8).gif"));
   
   //画布
   Graphics g = Graphics.FromImage(img);

   SolidBrush sb = new SolidBrush(Color.Red);

   Font f = new Font("宋体",14);
   //在图片上绘制水印
   g.DrawImage(waterImg,img.Width-waterImg.Width,img.Height -waterImg.Height);
   
   
   //显示
   img.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
 
   g.Dispose();

   waterImg.Dispose();
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

发布了23 篇原创文章 · 获赞 3 · 访问量 2万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章