using Image = System.Drawing.Image;

在Page_Load里调用下面代码,然后直接调用这个页面的url就是生成的图片了.

Image image = Image.FromFile(Server.MapPath("~/background.png"));

            Graphics g = Graphics.FromImage(image);

            try

            {

                ///

                  ////操作image对象代码

                ///

                //保存图片并通过Response输出流

                Response.Clear();

                Response.ContentType = "image/png";

                image.Save(Response.OutputStream, ImageFormat.Png);

            }

            finally

            {

                g.Dispose();

                image.Dispose();

            }

 

因为aspx调用动态生成硬盘文件的话会因为缓存同一个文件名无法刷新,而动态文件名则要放硬盘,读 完了还要删除,非常麻烦,所以通过aspx输出给其他控件直接用url调用

using Image = System.Drawing.Image;

在Page_Load里调用下面代码,然后直接调用这个页面的url就是生成的图片了.

Image image = Image.FromFile(Server.MapPath("~/background.png"));

            Graphics g = Graphics.FromImage(image);

            try

            {

                ///

                  ////操作image对象代码

                ///

                //保存图片并通过Response输出流

                Response.Clear();

                Response.ContentType = "image/png";

                image.Save(Response.OutputStream, ImageFormat.Png);

            }

            finally

            {

                g.Dispose();

                image.Dispose();

            }


作者:KKcat