C#添加图片水印
protected void Button2_Click1(object sender, EventArgs e)
{
//加图片水印
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("..") + "/bb.jpg"); ///原图地址
System.Drawing.Image copyImage = System.Drawing.Image.FromFile( Server.MapPath("..") + "/LOGO.PNG"); //水印图片
Graphics g = Graphics.FromImage(image);
// g.DrawImage(copyImage, new Rectangle(image.Width - copyImage.Width, 0, image.Width, copyImage.Height), 0, 0, image.Width, copyImage.Height, GraphicsUnit.Pixel);/// 右上方
// 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.DrawImage(copyImage, new Rectangle((image.Width - copyImage.Width) / 2, (image.Height - copyImage.Height) / 2, image.Width, copyImage.Height), 0, 0, image.Width, copyImage.Height, GraphicsUnit.Pixel);/// 正中间
///
// g.DrawImage(copyImage, new Rectangle(0, 0, image.Width, copyImage.Height), 0, 0, image.Width, copyImage.Height, GraphicsUnit.Pixel);/// 左上方
// g.DrawImage(copyImage, new Rectangle(0, image.Height - copyImage.Height, image.Width, copyImage.Height), 0, 0, image.Width, copyImage.Height, GraphicsUnit.Pixel);/// 左下方
g.DrawImage(copyImage, new Rectangle((image.Width - copyImage.Width) / 2, (image.Height - copyImage.Height) / 2, image.Width, copyImage.Height), 0, 0, image.Width, copyImage.Height, GraphicsUnit.Pixel);/// 正中间
g.Dispose();
string newPath = Server.MapPath("..") + "/IMG/BB.JPG";
image.Save(newPath);
image.Dispose();
}
}
{
//加图片水印
System.Drawing.Image image = System.Drawing.Image.FromFile(Server.MapPath("..") + "/bb.jpg"); ///原图地址
System.Drawing.Image copyImage = System.Drawing.Image.FromFile( Server.MapPath("..") + "/LOGO.PNG"); //水印图片
Graphics g = Graphics.FromImage(image);
// g.DrawImage(copyImage, new Rectangle(image.Width - copyImage.Width, 0, image.Width, copyImage.Height), 0, 0, image.Width, copyImage.Height, GraphicsUnit.Pixel);/// 右上方
// 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.DrawImage(copyImage, new Rectangle((image.Width - copyImage.Width) / 2, (image.Height - copyImage.Height) / 2, image.Width, copyImage.Height), 0, 0, image.Width, copyImage.Height, GraphicsUnit.Pixel);/// 正中间
///
// g.DrawImage(copyImage, new Rectangle(0, 0, image.Width, copyImage.Height), 0, 0, image.Width, copyImage.Height, GraphicsUnit.Pixel);/// 左上方
// g.DrawImage(copyImage, new Rectangle(0, image.Height - copyImage.Height, image.Width, copyImage.Height), 0, 0, image.Width, copyImage.Height, GraphicsUnit.Pixel);/// 左下方
g.DrawImage(copyImage, new Rectangle((image.Width - copyImage.Width) / 2, (image.Height - copyImage.Height) / 2, image.Width, copyImage.Height), 0, 0, image.Width, copyImage.Height, GraphicsUnit.Pixel);/// 正中间
g.Dispose();
string newPath = Server.MapPath("..") + "/IMG/BB.JPG";
image.Save(newPath);
image.Dispose();
}
}