asp教程.net 图片水印经典代码
防止图片被别人转载使用,我们会对图片进行水印处理。
using System;
using System.Web;
using System.Drawing;
using System.IO;
public class BookHandler : IHttpHandler {
private const string COVERSADDR = "~/Image/"; //封面文件夹路径
private const string WATERMARK_URL = "~/Images/WaterMark.jpg"; //数字水印路径
private const string DEFAULT_URL = "~/Images/default.jpg"; //默认图片路径
public void ProcessRequest (HttpContext context) {
string path = context.Request.MapPath(COVERSADDR + context.Request.Params["ISBN"].ToString() + ".jpg");
Image Cover;
if (File.Exists(path))
{
Cover = Image.FromFile(path);
Image watermark = Image.FromFile(context.Request.MapPath(WATERMARK_URL));
Graphics g = Graphics.FromImage(Cover);
g.DrawImage(watermark, new Rectangle(Cover.Width - watermark.Width, Cover.Height - watermark.Height, watermark.Width, watermark.Height), 0, 0, watermark.Width, watermark.Height, GraphicsUnit.Pixel);
g.Dispose();
watermark.Dispose();
}
else
{
Cover = Image.FromFile(context.Request.MapPath(DEFAULT_URL));
}
context.Request.ContentType = "image/ipeg";
Cover.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
Cover.Dispose();
context.Response.End();
}
public bool IsReusable {
get {
return false;
}
}
}
最后在页面或代码中将连接图片的路径都改成
BookCover.ashx?ISBN=数字就可以了
《黎明杀机》开发商正开发新的《Serious Sam》游戏 由Devolver发行
超英派遣中心即将登陆Xbox Play Anywhere 深入了解这款独特而备受喜爱的冒险游戏
在《Hunter: The Reckoning – Deathwish》中怎么从猎物蜕变为猎手
《The Expanse: Osiris Reborn》——深入了解玩法 新同伴 封闭测试及发行窗口
Alien Deathstorm 科幻生存与动作结合 打造全新第一人称恐怖混合体验
宝可梦公司已在考虑未来可用口袋妖怪总数达到“或许一万只”
幸存者村庄2
怪可爱的店折相思菜单
怪可爱的店折相思菜单是一款画风治愈的模拟经营佳作,内置折相思菜单解锁多项便利功能
lol电竞经理人手游
lol电竞经理人手游让你可以成为职业的电竞经理人,在游戏中掌控游戏的走向!豪华阵
梦幻奶茶屋小游戏
梦幻奶茶屋是一款主打温馨治愈氛围的休闲经营作品,玩家将化身元气满满的奶茶店店长,
萌宠养成物语无限金币版
萌宠养成物语无限金币版是一款治愈系模拟养成游戏,以可爱卡通画风构建温馨虚拟世界,