日期:2014-05-18  浏览次数:20841 次

动态添加的图片image,怎么销毁?
对于image对象总是要dispose()
[code=C#][/code]
  Image img = Image.FromFile(ofg.FileName);
  bmp = new Bitmap(img);
  if (pictureBox1.Width < bmp.Width || pictureBox1.Height < bmp.Height)
  zoom = Math.Min((float)pictureBox1.Width / (float)bmp.Width, (float)pictureBox1.Height / (float)bmp.Height);
  else
  zoom = 1.0f;
  img.Dispose();
  IsLoadBmp = true;
  pictureBox1.Refresh();]
这里转化成bitmap了,我要动态添加很多图片,怎么销毁?bitmap的就不用销毁了?

------解决方案--------------------
就是你用的Dispose
System.Drawing.Image img = System.Drawing.Image.FromFile(LotteryHelper.BackgroundImage);
System.Drawing.Image bmp = new System.Drawing.Bitmap(img);
img.Dispose();
this.BackgroundImage = bmp;
------解决方案--------------------
Bitmap继承自Image,要销毁都要调用它的Dipose()方法,然后调用GC.Collect()的,不然内存一下不会释放
------解决方案--------------------
dim bmp as new bitmap("c:\1.bmp")

循环显示:
for.....
if bmp isnot nothing then bmp.dispose '每次使用前先释放旧图片
bmp=new bitm("c:\1.bmp")
next