Dispose of a pictureBox image without losing the pictureBox

北城余情 提交于 2019-12-02 01:35:07

What is the number of images and total size? I think it is better to load all images in array and assign them to horPicBox than loading them multiple times. To use Dispose first assign horPicBox.Image to temp object, then assign horPicBox.Image to null or next image and call Dispose at the end for the temp object:

Image img = horPicBox.Image;
horPicBox.Image = Image.FromFile(imagePaths[index]);
if ( img != null ) img.Dispose();

What if you store the image to variable of that type and then set your picturebox image and then dispose the older one like

       Image oldImage = horPicBox.Image;
       horPicBox.Image = Image.FromFile(imagePaths[index]);
       oldImage.Dispose();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!