數字水印

<%@ 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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章