asp.net 给图片加水印--源码--调试成功

    public static void AddWater(string Path, string Path_sy)
    {
      
        string addText = "PerfectMan";
        System.Drawing.Image image = System.Drawing.Image.FromFile(Path);
        Graphics g = Graphics.FromImage(image);
        g.DrawImage(image, 0, 0, image.Width, image.Height);
        Font f = new Font("Verdana", 8);
        Brush b = new SolidBrush(Color.Red);
        g.DrawString(addText, f, b, 0, 0);
        g.Dispose();
        image.Save(Path_sy);
        image.Dispose();
            }

    ///  <summary>
    /// 在图片上生成图片水印
    ///  </summary>
    ///  <param name="Path">原服务器图片路径 </param>
    ///  <param name="Path_syp">生成的带图片水印的图片路径 </param>
    ///  <param name="Path_sypf">水印图片路径 </param>
    public static void AddWaterPic(string Path, string Path_syp, string Path_sypf)
    {
        System.Drawing.Image image = System.Drawing.Image.FromFile(Path);
        System.Drawing.Image copyImage = System.Drawing.Image.FromFile(Path_sypf);
        Graphics g = Graphics.FromImage(image);
        Rectangle rect = new Rectangle(image.Width - copyImage.Width, image.Height - copyImage.Height, copyImage.Width, copyImage.Height);
        g.DrawImage(copyImage, rect, 0, 0, copyImage.Width, copyImage.Height, GraphicsUnit.Pixel);
        g.Dispose();

        image.Save(Path_syp);
        image.Dispose();
    }

posted @ 2009-03-05 17:16  perfectMan  阅读(750)  评论(1)    收藏  举报