x,y是控制水印图片的位置的,目前是显示在右下角,如何让其显示为居中,如何计算 
int x =  newImage.Width - WaterImage.Width - 10;
 int y =  newImage.Height - WaterImage.Height - 10;
///开始绘制水印
                graphics.DrawImage(WaterImage, new Rectangle(x, y, WaterImage.Width, WaterImage.Height), 0, 0, WaterImage.Width, WaterImage.Height, GraphicsUnit.Pixel, attributes);
            

解决方案 »

  1.   

      /// <summary>
        /// 在封面图片上画水印
        /// </summary>
        /// <param name="context"></param>
        /// <param name="coverPath"></param>
        /// <param name="waterPath"></param>
        /// <param name="defaultPath"></param>
        public static void DrawWater(HttpContext context,string coverPath,string waterPath,string defaultPath)
        {
            System.Drawing.Image cover;
            //从磁盘中读取封面图片和默认图片保存到内存
            if (File.Exists(coverPath))
            {
                cover = System.Drawing.Image.FromFile(coverPath);
            }
            else
            {
                cover = System.Drawing.Image.FromFile(defaultPath);
            }        //从磁盘中读取水印图片到内存
            System.Drawing.Image water = System.Drawing.Image.FromFile(waterPath);        //定义封面图片为画布
            System.Drawing.Graphics gp = System.Drawing.Graphics.FromImage(cover);        //定义矩形
            Rectangle rg = new Rectangle(cover.Width - water.Width, cover.Height - water.Height, water.Width, water.Height);        //在画布(封面)上画水印
            gp.DrawImage(water,rg);        //将画好水印的封面保存到响应流中
            cover.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);        //释放资源
            gp.Dispose();
            water.Dispose();
            cover.Dispose();
        }