给图片增加水印
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.效果图