[原创]在ASP.NET中为图形加水印的方法 (C#版本)

使用Drawing ,IO命名空间,实际就是把图片拿出来用指定的font和brush画在现有的图像上。
本示例要求与ASPX页面相同的路径下有aaa.jpg这张图片,当然稍微大点好啦。
代码加载在Page.load事件处理程序里:
            string filePath=Server.MapPath("aaa.jpg");

            System.Drawing.Image image
=System.Drawing.Image.FromFile(filePath);
            Graphics graphic
=Graphics.FromImage(image);
            graphic.DrawImage(image,
0,0,image.Width,image.Height);

            Font font
=new Font("Verdana",30);
            Brush brush
=new SolidBrush(Color.Teal);
            graphic.DrawString(
"Hi,I am Gaoy.",font,brush,20,10);

            image.Save(Response.OutputStream,System.Drawing.Imaging.ImageFormat.Jpeg);

            graphic.Dispose();
            image.Dispose();
posted on 2006-09-29 17:43  雪无止境  阅读(432)  评论(2编辑  收藏  举报