1.新建web窗体添加后缀名为“.aspx”的界面
2.添加一个文件夹名为“Image” 然后将所需图片放入进去,然后再到div里添加如下代码:
<div>
<img src="images/1.jpg" />
<img src="images/2.jpg" />
<img src="images/3.jpg" />
<img src="images/4.jpg" />
</div>
3.添加“MyModule”类 ,实现接口。代码如下:
public class MyModule : IHttpModule
{
public void Dispose()
{
}
public void Init(HttpApplication context)
{
context.BeginRequest += Context_BeginRequest;
context.EndRequest += Context_EndRequest;
}
private void Context_EndRequest(object sender, EventArgs e)
{
HttpApplication context = sender as HttpApplication;
}
private void Context_BeginRequest(object sender, EventArgs e)
{
HttpApplication context = sender as HttpApplication;
}
}
4.添加名为“MyHandler”类,实现接口。代码如下:
public class MyHandler : IHttpHandler
{
public bool IsReusable => false;
public void ProcessRequest(HttpContext context)
{
string filename = context.Request.PhysicalPath;
Bitmap map = new Bitmap(filename);
Graphics gra = Graphics.FromImage(map);
gra.DrawString("哇哦", new Font("微软雅黑", 100, FontStyle.Bold), Brushes.White, new Point(50, 50));
gra.Flush();
map.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
}
5.到“Web.config”界面添加如下代码:
<system.webServer>
<modules>
<add name="modules1" type="website.MyModule"/>
</modules>
<handlers>
<add verb="*" path="images/*.JPG" type="website.MyHandler" name="plink"/>
</handlers>
</system.webServer>
最后,一个水印就这么做好了