MyImage  定义为外部变量
MyImage = new Bitmap(fileName); 
 
定时器中每次重新装载图像
 if (this.PictureBox.Image != null)
{
    this.PictureBox.Image.Dispose();
    this.PictureBox.Image = null;
}
this.ctrlPictureBox.Image = MyImage;编译时,提示参数错误修改为
if (this.PictureBox.Image != null)
{
    this.PictureBox.Image.Dispose();
    this.PictureBox.Image = null;
}
this.PictureBox.Image = (Image)MyImage.Clone();图像显示时闪烁修改为
if (this.PictureBox.Image != null)
{
    this.PictureBox.Image.Dispose();
}
this.PictureBox.Image = (Image)MyImage.Clone();
内存递增各位老大看看,解释一下。谢谢了。

解决方案 »

  1.   

    你Clone就相当于把这个对象复制了一次,当然内存会递增了。
      

  2.   

    MyImage  定义为外部变量 
    MyImage = new Bitmap(fileName); 定时器中每次重新装载图像 
    if (this.PictureBox.Image != null) 

        this.PictureBox.Image.Dispose(); 
        this.PictureBox.Image = null; 

    this.ctrlPictureBox.Image = MyImage; 编译时,提示参数错误 
    什么错误?这段代码应该是可以的,用类似的代码我是可以编译成功的。
      

  3.   

    MyImage  定义为外部变量 
    MyImage = new Bitmap(fileName); 
    以上部分在初始化部分赋值在定时器中实现图片的更换。
    void timer_tick()
    {
    if (this.PictureBox.Image != null) 

        this.PictureBox.Image.Dispose(); 
        this.PictureBox.Image = null; 

    this.ctrlPictureBox.Image = MyImage; }
    程序运行时提示参数异常。
      

  4.   

    修改为如下,运行正常,但是内存递增
    void timer_tick() 

    if (this.PictureBox.Image != null) 

        this.PictureBox.Image.Dispose(); 
        this.PictureBox.Image = null; 

    MyImage = new Bitmap(filename);
    this.ctrlPictureBox.Image = MyImage; } 
      

  5.   

    MyImage = new Bitmap(filename); 
    你不断的把它实例化,内存肯定会增加啊