调用函数部分
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string saveasPath = @"f:\mywork\images\Showimg.jpg";
AddImageWatermark(saveasPath);
//sc();
bz();
}
/// <summary>
/// 加水印并保存图
/// </summary>
/// <param name="strOraginalPath"></param>
public void AddImageWatermark(string strOraginalPath)
{
string strWatermarkImagePath = HttpContext.Current.Server.MapPath("images/watermark.gif");
System.Drawing.Image imgOraginal = System.Drawing.Image.FromFile(strOraginalPath);
int iOraginalWidth = imgOraginal.Width;
int iOraginalHeight = imgOraginal.Height;
System.Drawing.Bitmap bitOraginal = new System.Drawing.Bitmap(imgOraginal, iOraginalWidth, iOraginalHeight);
imgOraginal.Dispose();
System.Drawing.Graphics gOraginal = System.Drawing.Graphics.FromImage(bitOraginal);
//System.Drawing.Rectangle rectTextField = new System.Drawing.Rectangle(10, 10, iWidth - 20, iHeight - 20);
System.Drawing.Image imgWatermark = System.Drawing.Image.FromFile(strWatermarkImagePath);
int iWatermarkWidth = imgWatermark.Width;
int iWatermarkHeight = imgWatermark.Height;
System.Drawing.Rectangle rect;
int iHCenter = (iOraginalWidth - iWatermarkWidth) / 2;
int iVCenter = (iOraginalHeight - iWatermarkHeight) / 2;
int iHRight = (iOraginalWidth - iWatermarkWidth - 10);
int iVBottom = (iOraginalHeight - iWatermarkHeight - 10);
//水印的位置
rect = new System.Drawing.Rectangle(iHRight, iVBottom, iWatermarkWidth, iWatermarkHeight);
gOraginal.DrawImage(imgWatermark, rect);
bitOraginal.Save(strOraginalPath, System.Drawing.Imaging.ImageFormat.Jpeg);
bitOraginal.Dispose();
gOraginal.Dispose();
imgWatermark.Dispose();
}