Backup/WEB/ImgHttpHandler.ashx.cs

(完整代码) 1KB

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.IO;
using System.Drawing;

namespace WEB
{
    /// <summary>
    /// ImgHttpHandler 的摘要说明
    /// </summary>
    public class ImgHttpHandler : IHttpHandler
    {
        //默认图片路径
        private const string Img = "~/img/9.jpg";

        public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");
            string path = context.Request.MapPath(Img);
            System.Drawing.Image Cover;
            if(File.Exists(path))  //图片存在则添加水晶印
            {
                //加载图片文件
                Cover = Image.FromFile(path);
                //实例化画布
                Graphics g = Graphics.FromImage(Cover);
                //设置字体
                Font font = new Font("华文行楷",20);
                //在图片上绘制水印
                g.DrawString("生时何必久睡,死后自会长眠!!",font,Brushes.Blue,0,Cover.Height-font.Height);
                //释放画布
                g.Dispose();
                //设置输出图片类型
                context.Response.ContentType = "image/jpeg";
                //将修改图片存入
                Cover.Save(context.Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);
                Cover.Dispose();
                context.Response.End();
            }
        }
        
        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。