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;

        }
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM