C#图片增加水印

给图片增加水印 

 

1.引用

using System.Drawing;

 

2.代码实现

            string ImagePath = @"C:\Users\RAPOO\Pictures\Camera Roll\wuhan.jpg";

            try
            {
                Image image = Image.FromFile(ImagePath);

                Graphics g = Graphics.FromImage(image);

                //水印内容
                string waterText = "wangyblzu";

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

                //用于确定水印的大小
                SizeF zisizeF = new SizeF();
                zisizeF = g.MeasureString(waterText, font);

                //亮度,红色,绿色,蓝色
                SolidBrush solidBrush = new SolidBrush(Color.FromArgb(255, 255, 0, 0));

                //水印
                g.DrawString(waterText, font, solidBrush, new PointF(image.Width / 5, image.Height / 2 - zisizeF.Height / 2));

                //图片另存
                image.Save(@"C:\Users\RAPOO\Pictures\Camera Roll\wuhan2.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (Exception ex)
            { 
                
            }

 

3.效果图

 

posted on 2016-09-07 14:59  wangyblzu  阅读(2372)  评论(0编辑  收藏  举报

导航