File lock problem with Image.FromFile()
-
Hi, when I load an image using this
Bitmap bitmap = (Bitmap)Image.FromFile(pic.Path)
, it is not possible to delete the file afterwards, unless you exit the program. I tried to call.Dispose()
on the object, but it seems like a bug in theFromFile
method. I found out a workaroundBitmap origbmp = new Bitmap(pic.Path); Bitmap bitmap = new Bitmap(origbmp); origbmp.Dispose();
. I keep working with the copy of the original bitmap as it's not locked anymore. But, loading an image usingBitmap
's constructor, it's impossible to load animated GIFs as it seems thatBitmap
doesn't support them. Now, how can I use animated GIFs and other image formats AND be able to delete the file afterwards? Thx :-D Stefan -
Hi, when I load an image using this
Bitmap bitmap = (Bitmap)Image.FromFile(pic.Path)
, it is not possible to delete the file afterwards, unless you exit the program. I tried to call.Dispose()
on the object, but it seems like a bug in theFromFile
method. I found out a workaroundBitmap origbmp = new Bitmap(pic.Path); Bitmap bitmap = new Bitmap(origbmp); origbmp.Dispose();
. I keep working with the copy of the original bitmap as it's not locked anymore. But, loading an image usingBitmap
's constructor, it's impossible to load animated GIFs as it seems thatBitmap
doesn't support them. Now, how can I use animated GIFs and other image formats AND be able to delete the file afterwards? Thx :-D Stefan