C#上传图片添加水印
using (var memoryStream = new MemoryStream()) { file.CopyTo(memoryStream); using (var img = Image.FromStream(memoryStream)) { if (GlobalData.SiteData.EnableImageMask) { using (Graphics g = Graphics.FromImage(img)) { Font drawFont = new Font("宋体", 24f); SolidBrush drawBrush = new SolidBrush(Color.FromArgb(75, Color.Black)); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; var mtxSave = g.Transform; var mtxRotate = g.Transform; mtxRotate.RotateAt(-45, new PointF(img.Width / 2, img.Height / 2)); g.Transform = mtxRotate; //g.DrawString("YES dotnet开发平台", drawFont, drawBrush, new RectangleF(0, 0, img.Width, img.Height-20), sf); //g.DrawString("www.yesdotnet.com", drawFont, drawBrush, new RectangleF(0, 20, img.Width, img.Height), sf); //g.DrawString("YES dotnet开发平台" + System.Environment.NewLine + "www.yesdotnet.com", drawFont, drawBrush, new RectangleF(0, 0, img.Width, img.Height), sf); g.DrawString(GlobalData.SiteData.ImageMaskValue, drawFont, drawBrush, new RectangleF(0, 0, img.Width, img.Height), sf); g.Transform = mtxSave; } } img.Save(filename); } }
GarsonZhang www.yesdotnet.com
效果:
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post YES开发框架