c# picturebox memory releasing problem

前端 未结 3 1180
别那么骄傲
别那么骄傲 2020-12-17 17:50

I\'m a newby in C#. I have to repeatedly refresh a GUI picture box in a worker thread. The image is acquired from a camera polling a driver with a GetImage method that retri

3条回答
  •  天命终不由人
    2020-12-17 18:20

    There are several ways to release an image from pbox. I strongly recommend the way is that do not use pbox.Image = Image.FromFile.... If you do not use FileStream and you want to read it from file use BitMap class. Like this:

    Bitmap bmp = new Bitmap(fileName);
    pbox.Image = bmp; // notice that we used bitmap class to initialize pbox.
    

    ... and then you want to release the image file bmp.Dispose();
    Now you can delete, move or whatever you want to the file.

提交回复
热议问题