asp.net MVC 图片水印和文字水印
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
//type传入参数类型是图片水印还是文字水印 public void addStrToImage(string type) { string path = System.Web.HttpContext.Current.Server.MapPath("/Images/") + "WarterImage.jpg"; System.Drawing.Image image = System.Drawing.Image.FromFile(path); if (type == "文字") { //加文字水印.文字和图片水印如果共存请加判断 Graphics g = Graphics.FromImage(image); g.DrawImage(image, 0, 0, image.Width, image.Height); Font f = new Font("Verdana", 32);//文字字体 Brush b = new SolidBrush(Color.White);//文字颜色 string addText = "123";//要加的文字 g.DrawString(addText, f, b, 10, 10); g.Dispose(); } else { ////加图片水印 System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Server.MapPath(".") + "/pic.gif"); Graphics g = Graphics.FromImage(image); g.DrawImage(copyImage, new Rectangle(image.Width - copyImage.Width, image.Height - copyImage.Height, copyImage.Width, copyImage.Height), 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel); g.Dispose(); } //保存加水印过后的图片 image.Save(path + "thum.JPG"); image.Dispose(); }