Dispose of a pictureBox image without losing the pictureBox

前端 未结 2 523
栀梦
栀梦 2021-01-23 02:01

I am writing a program that will play a slideshow (among other things). The slideshow is controlled by a backgroundWorker, and is set to a while(true) loop so it will constantly

2条回答
  •  粉色の甜心
    2021-01-23 02:24

    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();
    

提交回复
热议问题