Overwrite an image after unload it from a picture box control
-
After I unloaded an image from a picture box like that:
if (pictureBox.Image != null){ pictureBox.Image.Dispose(); pictureBox.Image = null; }
but when the application is still running, I cannot overwrite this image. How can overwrite it while application is still running? Thanks a lot! I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing -
After I unloaded an image from a picture box like that:
if (pictureBox.Image != null){ pictureBox.Image.Dispose(); pictureBox.Image = null; }
but when the application is still running, I cannot overwrite this image. How can overwrite it while application is still running? Thanks a lot! I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of NothingI would hope that the picturebox takes care of it's own memory, and you can just assign another image. Christian Graus - Microsoft MVP - C++
-
I would hope that the picturebox takes care of it's own memory, and you can just assign another image. Christian Graus - Microsoft MVP - C++
Maybe my description has some confusions for you. I don't want to load another image to the pictrue box, I want my program can overwrite the image which I just have unload from the picture box. I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing
-
Maybe my description has some confusions for you. I don't want to load another image to the pictrue box, I want my program can overwrite the image which I just have unload from the picture box. I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing
Are you saying that the picturebox continues to hold a reference to the image, and the image on disc cannot be overwritten as a result ? That seems odd to me, I don't think that Bitmap.FromFile keeps the file open. Christian Graus - Microsoft MVP - C++
-
Are you saying that the picturebox continues to hold a reference to the image, and the image on disc cannot be overwritten as a result ? That seems odd to me, I don't think that Bitmap.FromFile keeps the file open. Christian Graus - Microsoft MVP - C++
-
Extractly! But I don't use Bitmap.FromFile, I used pictureBox.Load(). I'm ... a fan of Manchester United a fan of Ozzy Osbourne a King of Nothing
The picture box is crap. I dunno why so many people use it. First step, use Bitmap.FromFile, and pass that bitmap in, instead. Then, I don't see you having any issues. Christian Graus - Microsoft MVP - C++
-
The picture box is crap. I dunno why so many people use it. First step, use Bitmap.FromFile, and pass that bitmap in, instead. Then, I don't see you having any issues. Christian Graus - Microsoft MVP - C++
-
Are you saying that the picturebox continues to hold a reference to the image, and the image on disc cannot be overwritten as a result ? That seems odd to me, I don't think that Bitmap.FromFile keeps the file open. Christian Graus - Microsoft MVP - C++
The Bitmap class inherits from Image and uses Image's FromFile method, which calls a GDI+ Flat API function in GDIPlus.dll (curiously, something you're NOT supposed to do), called
GdipLoadImageFromFile
to load the image file. It looks like the resulting file handle is never closed so long as the GDI+ Image object exists. As you probably know, the usual workaround was this[^] little article on MSDN. This eventually uses theGdipLoadImageFromStream
GDI+ function, which does not hold a handle to the original image stream. In 2005, thePictureBox.Load
method calls the staticImage.FromStream
method, no matter what the actual source of the image is, so locking the image file is not a problem. But, to answer his question,PictureBox.Image = null;
should work no problem. I didn't have any at least... ;) RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome