代码如下:
public partial class picture : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
       
    }
    protected void btnChange_Click(object sender, EventArgs e)
    {
        Font rectanglefont = new Font("Arial", 10, FontStyle.Bold);        int height = 100;
        int width = 200;        Random r = new Random();
        int x = r.Next(75);
        int a = r.Next(155);
        int x1 = r.Next(100);        Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
        Graphics g = Graphics.FromImage(bmp);
        g.SmoothingMode = SmoothingMode.AntiAlias;
        g.Clear(Color.LightGray);        g.DrawRectangle(Pens.White, 1, 1, width - 3, height - 3);
        g.DrawRectangle(Pens.Aquamarine, 2, 2, width - 3, height - 3);
        g.DrawRectangle(Pens.Black, 0, 0, width, height);        g.DrawString("ASP.NET Samples", rectanglefont, SystemBrushes.WindowText, new PointF(10, 40));        g.FillRectangle(new SolidBrush(Color.FromArgb(a, 225, 128, 255)), x, 20, 100, 50);
        g.FillRectangle(new LinearGradientBrush(new Point(x, 10), new Point(x1 + 75, 50 + 30), Color.FromArgb(128, 0, 0, 128), Color.FromArgb(255, 255, 255, 240)), x1, 50, 75, 30);
        FileStream fs = File.Create(Server.MapPath("~/picture.jpeg"));
        bmp.Save(fs, ImageFormat.Jpeg);
        im1.ImageUrl = Server.MapPath("~/picture.jpeg");
        bmp.Dispose();
        g.Dispose();
    }
}
以上代码先是在Page_Load事件里面,然后我在页面上一个image控件和一个按钮,讲以上代码剪切到按钮的click事件里面
我想单击按钮的时候,产生一个图片,保存在当前文件夹里面,然后在image里面显示出来。
但是,当我打开页面还没点按钮的时候,image里面的图片就出现了
请问这是不是因为图片还在内存里面没有清除啊?
怎么解决呢?
望各位帮帮忙

解决方案 »

  1.   

    清除下缓存看看前台页面就一个img控件吗?Font rectanglefont = new Font("Arial", 10, FontStyle.Bold);打个断点 清空缓存调试看走没走
      

  2.   

    清了的,但是不行
    页面上面就一个image和Button
      

  3.   

    im1.ImageUrl = Server.MapPath("~/picture.jpeg");
    应该为:
    im1.ImageUrl = "~/picture.jpeg";另外应该还要加:
    fs.Dispose();
      

  4.   

    你的这种方法试了的,还是不行
    在前面还把fs.close()了,也不行
      

  5.   


    允许我弱弱滴问一句:在哪里停VS服务额?我在“服务”里面找了都没找到,只看到一个vs2008 remote debugger。它已经是禁用状态