zoukankan      html  css  js  c++  java
  • 图片水印与文字水印

    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Web;
    using System.IO;
    1 
    // Draw the image in the bottom-right corner 图片右下角
    using (System.Drawing.Image watermark = System.Drawing.Image.FromFile(HttpContext.Current.Server.MapPath("~/Gfx/Watermark.png")))
    {
        using (Graphics g = Graphics.FromImage(args.Image))
        {
            // Setup the quality settings (max)
            g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
            g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
    
            // Draw the image
            g.DrawImageUnscaled(watermark, args.Image.Width - watermark.Width, args.Image.Height - watermark.Height, watermark.Width, watermark.Height);
    
            g.Dispose();
        }
    }

    2

    // Draw the text in the bottom-right corner
    using (Graphics g = Graphics.FromImage(args.Image))
    {
        string text = "MyLogo";
        Font font = new Font(FontFamily.GenericSansSerif, 14, FontStyle.Bold);
        SizeF stringSize = g.MeasureString(text, font);
        PointF location = new PointF(args.Image.Width - stringSize.Width - 10, args.Image.Height - stringSize.Height - 10);
    
        // Setup the quality settings
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    
        // Draw the text
        g.DrawString(text, font, Brushes.Red, location);
    
        g.Dispose();
    }

    水印在图片中心 这个图只截取了一部分

    3

    using (Graphics g = Graphics.FromImage(args.Image))
    {
        // Draw a horizontal text in the image center
        string text = "My NEW watermark";
        Font font = new Font(FontFamily.GenericSansSerif, 24, FontStyle.Bold);
        SizeF stringSize = g.MeasureString(text, font);
        PointF location = new PointF((args.Image.Width - stringSize.Width) / 2, (args.Image.Height - stringSize.Height) / 2);
        
        // Setup the quality settings
        g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
    
        // Draw the text
        g.DrawString(text, font, new SolidBrush(Color.FromArgb(85, 255, 255, 80)), location);
    
        // Draw a vertical text in the bottom-right corner
        DateTime dt = DateTime.UtcNow;
        text = "My watermark - " + dt.ToString("s");
        font = new Font(FontFamily.GenericSansSerif, 9, FontStyle.Bold);
        StringFormat stringFormat = new StringFormat();
        stringFormat.FormatFlags = StringFormatFlags.DirectionVertical;
        stringSize = g.MeasureString(text, font, 100, stringFormat);
        location = new PointF(args.Image.Width - stringSize.Width - 5, args.Image.Height - stringSize.Height - 5);
    
        // Draw another text
        g.DrawString(text, font, new SolidBrush(Color.FromArgb(80, 255, 255, 255)), location, stringFormat);
    
        g.Dispose();
    }

  • 相关阅读:
    2018最新php笔试题及答案(持续更新)
    快速上手模板制作
    春节期间小游戏同时在线人数最高达2800万人/小时
    公众平台新增修改文章错别字功能 每篇文章允许被修改一次仅限正文内五个字
    微信6.6.2版更新:支持两个账号一键切换
    小程序支持打开APP了 还有小程序的标题栏也可以自定义
    小程序发布重磅数据:日活跃用户数1.7亿、已上线小程序58万个,覆盖100万开发者、2300个第三方平台
    张小龙2018PRO版微信公开课演讲全文 透露2018微信全新计划
    除了跳一跳还有16款微信小游戏可以玩
    小游戏里潜藏着600亿的大市场
  • 原文地址:https://www.cnblogs.com/zengxiangzhan/p/1633447.html
Copyright © 2011-2022 走看看