using (System.Drawing.Image sourceImage = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath(sSavePath + sFilename)))
{
int width = sourceImage.Width;//图片宽
int height = sourceImage.Height;//图片长}
{
int width = sourceImage.Width;//图片宽
int height = sourceImage.Height;//图片长}
using (System.Drawing.Image sourceImage = System.Drawing.Image.FromFile(System.Web.HttpContext.Current.Server.MapPath(sSavePath + sFilename)))
{
//int width = sourceImage.Width;//图片宽
//int height = sourceImage.Height;//图片长 //获取图片的宽和高
int imgWidth = sourceImage.Width;
int imgHeight = sourceImage.Height; //建立一个bitmap,和我们需要加水印的图片一样大小
Bitmap bmPhoto = new Bitmap(imgWidth, imgHeight, PixelFormat.Format24bppRgb); //SetResolution:设置此 Bitmap 的分辨率
//这里直接将我们需要添加水印的图片的分辨率赋给bitmap
bmPhoto.SetResolution(sourceImage.HorizontalResolution, sourceImage.VerticalResolution); //Graphics:封装一个 GDI+ 绘图图面。
Graphics grPhoto = Graphics.FromImage(bmPhoto); //字体
Font crFont = new Font("宋体", 12, FontStyle.Bold);
SizeF crSize = new SizeF();
crSize = grPhoto.MeasureString(waterWords, crFont); int fntWidth = crSize.Width;
int fntHeight = crSize.Height; //定位水印文字的位置
float xPos = (imgWidth - fntWidth) / 2;
float yPos = (imgHeight - fntHeight) / 2;}