/**/ /// <summary> /// 添加单张图片文字水印 /// </summary> /// <param name="path">图片路径</param> /// <param name="fileName">图片名称(含后缀)</param> /// <param name="word">水印文字</param> public string AddWatermarkOne( string path, string fileName, string word) ... { //加文字水印 System.Drawing.Image image = System.Drawing.Image.FromFile(path+"/"+fileName); //获取图片 System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(image.Width, image.Height); //把图片转换成位图 Graphics g = Graphics.FromImage(bitmap); //画笔,制图 g.DrawImage(image, 0, 0, image.Width, image.Height); Font f = new Font("Verdana", 10); //字体,大小 Brush b = new SolidBrush(Color.Red); //字体颜色 g.DrawString(word, f, b, 35, 35); //开始画,及位置 g.Dispose(); //保存加水印过后的图片,删除原始图片 string newPath = path + "/new_" + fileName; //生成加入水印的新图片名字 bitmap.Save(newPath); //保存新图片 // bitmap.Dispose(); image.Dispose(); if (File.Exists(path+"/"+fileName)) //判断以前的图片是否存在,存在删除 ...{ File.Delete(path + "/" + fileName); } fileName = "new_" + fileName; return fileName; }