using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Drawing; using System.Drawing.Imaging; using System.IO;
生成有水印的圖片代碼
namespace TestHandler
{
public class NumberBackGround : IHttpHandler
{
public bool IsReusable
{
get
{
return false;
}
}
public void Proce***equest(HttpContext context)
{
//獲取物理路徑
string path = context.Request.PhysicalPath;
//獲取水印路徑
string logo = context.Server.MapPath("~/images/logo.jpg");
Image img = Image.FromFile(path);
Graphics g = Graphics.FromImage(img);
//噴logo
Image imgLogo = Image.FromFile(logo);
float x=(float)(img.Width-1000);
float y = (float)(img.Height -200);
g.DrawImage(imgLogo,new RectangleF(x,y,1000f,200f));
//處理後場景以圖片形式在客戶端響應
img.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
img.Dispose();
imgLogo.Dispose();
}
}
web.config配置
在<system.web>節點下面添加
<httpHandlers>
<add verb="*" path="images/*.jpg" type="NumberBackGround"/>
</httpHandlers>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.