• C#图片水印--简单实现


    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Drawing;
    namespace 图片水印
    {
        /// <summary>
        /// 水印类
        /// </summary>
        public class WaterMark
        {
            private string ImagePath = null;
            private Image bm = null;
            public WaterMark() { }
            public WaterMark(string ImagePath)
            {
                this.ImagePath = ImagePath;
            }
            public WaterMark(Image b)
            {
                this.bm = b;
            }
            public Image Draw(string content)
            {
                Image image = null;
                if (ImagePath != null)
                {
                    try
                    {
                        image = Image.FromFile(this.ImagePath);
                    }
                    catch
                    {
                        return null;
                    }
    
                }
                if (bm != null)
                {
                    image = this.bm;
                }
                Graphics g = Graphics.FromImage(image);
                StringFormat sf = new StringFormat();
                sf.Alignment = StringAlignment.Far;
    
                sf.LineAlignment = StringAlignment.Far;
                RectangleF rf = new RectangleF(0,0,image.Width,image.Height);
              
                g.DrawString(content, new Font("宋体", 40), Brushes.Red,rf,sf);
                g.Dispose();
                return image;
    
            }
        }
    }
    Hold on, everything is possible.
  • 相关阅读:
    然乌湖
    邦达 八宿
    芒康
    巴塘
    禾尼乡 所波大叔
    世界高城 理塘
    相克宗 藏民家
    骑行川藏--新都桥&塔公草原
    d 3
    D2
  • 原文地址:https://www.cnblogs.com/student-note/p/6496508.html
Copyright © 2020-2023  润新知