首先创建第一个网站,准备图片资源
在网站图片中添加HttpHandler类继承lHttpHandler接口
编写添加水印的功能 代码如下:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Web;
namespace WebApplication1
{
public class MyHandler:IHttpHandler
{
public bool IsReusable => false;
public void ProcessRequest(HttpContext context)
{
//得到用户请求的图片
String filename = context.Request.PhysicalPath;
Bitmap bitmap = new Bitmap(filename);
//实例化画布
Graphics graphics = Graphics.FromImage(bitmap);
//在image上绘制水印
graphics.DrawString("叼毛", new Font("宋体", 40, FontStyle.Bold), Brushes.Red, new Point(0, 0));
graphics.Flush();
bitmap.Save(context.Response