一般处理程序画图打水印

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

namespace CZBK.ItcastProject.WebApp._2015_5_27
{
    /// <summary>
    /// MakeImage 的摘要说明
    /// </summary>
    public class MakeImage : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/html";
            //给用户创建一张图片,并把这张图片保存。
            //创建一张画布
            using (Bitmap map=new Bitmap(300,400))
            {
                //给画布创建一个画笔
                using (Graphics g=Graphics.FromImage(map))
                {
                    //用画笔清除画布绘图面并以颜色填充
                    g.Clear(Color.Gray);
                    //在画布上写字,参数:写的字,字体样式,字体颜色,填充位置
                    g.DrawString("打上水印,哈哈哈", new Font("黑体", 14.0f, FontStyle.Bold), Brushes.Red,new PointF(150,200));
                    //将画布保存成一张图片
                    string fileName=Guid.NewGuid().ToString();
                    //将画布保存成一张图片并指定图片的类型。
                    map.Save(context.Request.MapPath("/ImageUpload/" + fileName + ".jpg"),System.Drawing.Imaging.ImageFormat.Jpeg);
                    //
                    context.Response.Write("<html><body><img src='/ImageUpload/" + fileName + ".jpg" + "' /></body></html>");
                }
            }

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
原文地址:https://www.cnblogs.com/wyt007/p/6099142.html