• 图片水印与文字水印


    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();
    }

  • 相关阅读:
    VS 对话框控件的Tab顺序问题
    基于OpenGL三维软件开发
    OpenGL 中的三维纹理操作
    VC 在桌面上绘制一些图形
    VC/MFC如何添加启动界面
    Cordova or Xamarin 用.net开发IOS和Android程序
    ASP.NET Web API
    软件项目如何选型
    CIO的职责、条件及价值
    Oracle日期周详解IW
  • 原文地址:https://www.cnblogs.com/zengxiangzhan/p/1633447.html
Copyright © 2020-2023  润新知