日期:2014-05-17 浏览次数:20434 次
/// <summary>
/// 对一个指定的图片加上图片水印效果。
/// </summary>
/// <param name="imageFile">图片文件地址</param>
/// <param name="waterImage">水印图片(Image对象)</param>
public static void CreateImageWaterMark(string imageFile, System.Drawing.Image waterImage)
{
if (string.IsNullOrEmpty(imageFile)
------解决方案--------------------
!File.Exists(imageFile)
------解决方案--------------------
waterImage == null)
{
return;
}
System.Drawing.Image originalImage = System.Drawing.Image.FromFile(imageFile);
if (originalImage.Width - 10 < waterImage.Width
------解决方案--------------------
originalImage.Height - 10 < waterImage.Height)
{
return;
}
Graphics graphics = Graphics.FromImage(originalImage);
int x = originalImage.Width - waterImage.Width - 10;
int y = originalImage.Height - waterImage.Height - 10;
int width = waterImage.Width;
int height = waterImage.Height;
graphics.DrawImage(waterImage, new Rectangle(x, y, width, height), 0, 0, width, height, GraphicsUnit.Pixel);
graphics.Dispose();
MemoryStream stream = new MemoryStream();
originalImage.Save(stream, ImageFormat.Jpeg);
originalImage.Dispose();
System.Drawing.Image imageWithWater = System.Drawing.Image.FromStream(stream);
imageWithWater.Save(imageFile);
imageWithWater.Dispose();
}