It seems that when I load a System.Drawing.Bitmap object
from a disk file using the constructor (the one that
accepts only one string [the filename]), then try to do
a .Save() on it passing in a string representing the
filename, it will produce an exception if the filename I
pass to Save() is the same one I used to load the bitmap.
The exception raised is:
System.Runtime.InteropServices.ExternalException
Additional information: A generic error occurred in GDI+.
If I pass in a different filename to Save() it works fine, or if I
create a new Bitmap by just specifying width and height
(not filename) then .Save() it, it works fine.
What is perhaps the strangest thing of all, is that if
right before I try my .Save(), if I do a .ShowDialog() on
a SaveFileDialog control, the Bitmap.Save() will always
work. Even though I do absolutely nothing with the
result from the dialog, and it doesnt matter what file I
select in the dialog (or even if I press cancel).
My theory is that the Bitmap is somehow holding onto the
file that it loads itself from. And that when I try to
save it, it raises that exception because the file is not
ready to be overwritten. Now my questions would be, how
do I make it so that I can successfully Save my bitmap,
and what the heck is the SaveFileDialog.ShowDialog()
doing that makes Bitmap.Save() work?
from a disk file using the constructor (the one that
accepts only one string [the filename]), then try to do
a .Save() on it passing in a string representing the
filename, it will produce an exception if the filename I
pass to Save() is the same one I used to load the bitmap.
The exception raised is:
System.Runtime.InteropServices.ExternalException
Additional information: A generic error occurred in GDI+.
If I pass in a different filename to Save() it works fine, or if I
create a new Bitmap by just specifying width and height
(not filename) then .Save() it, it works fine.
What is perhaps the strangest thing of all, is that if
right before I try my .Save(), if I do a .ShowDialog() on
a SaveFileDialog control, the Bitmap.Save() will always
work. Even though I do absolutely nothing with the
result from the dialog, and it doesnt matter what file I
select in the dialog (or even if I press cancel).
My theory is that the Bitmap is somehow holding onto the
file that it loads itself from. And that when I try to
save it, it raises that exception because the file is not
ready to be overwritten. Now my questions would be, how
do I make it so that I can successfully Save my bitmap,
and what the heck is the SaveFileDialog.ShowDialog()
doing that makes Bitmap.Save() work?