最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net图片加水印代码
时间:2022-06-25 06:10:46 编辑:袖梨 来源:一聚教程网
<%@ webhandler language="c#" class="bookhandler" %>
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=数字就可以了
在iis要配置一下jpg访问
相关文章
- 王者荣耀侦探能力大测试攻略 王者荣耀侦探能力大测试怎么过 11-22
- 无期迷途主线前瞻兑换码是什么 11-22
- 原神欧洛伦怎么培养 11-22
- 炉石传说网易云音乐联动怎么玩 11-22
- 永劫无间手游确幸转盘怎么样 11-22
- 无期迷途主线前瞻兑换码是什么 无期迷途主线前瞻直播兑换码介绍 11-22