故如虹,知恩;故如月,知明
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术

handler画图制作图片水印

4212人阅读 2019/3/14 9:06 总访问:3842135 评论:0 收藏:0 手机
分类: .NET


handler画图制作图片水印,版权申明什么的,直接上代码

  public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            //构建一个图片
            Bitmap bitmap = new Bitmap(context.Server.MapPath("~/img/mm.jpg"));

            //给图片关联一个画图类
            Graphics grap = Graphics.FromImage(bitmap);


            Font font = new Font("宋体", 13);

            SolidBrush probrush = new SolidBrush(Color.Purple);
            SolidBrush redbrush = new SolidBrush(Color.Red);

            grap.DrawString("放开那个女孩", font, redbrush, 30, 30);

            //画笔
            Pen redpen = new Pen(redbrush, 2);
            Pen propen = new Pen(probrush, 2);

            //画直线
            grap.DrawLine(redpen, 20, 20, 140, 140);
            grap.DrawLine(redpen, 140, 60, 140, 140);
            grap.DrawLine(redpen, 60, 140, 140, 140);

            //画图椭圆(根据矩形来截取得椭圆)
            grap.DrawEllipse(propen, 30, 30, 100, 100);
            //画矩形
            grap.DrawRectangle(redpen, 30, 30, 150, 100);

            //输出图片(借助流,输出流)
            bitmap.Save(context.Response.OutputStream, ImageFormat.Jpeg);
        }

一点效果:






欢迎加群讨论技术,群:677373950(满了,可以加,但通过不了),2群:656732739

评价