public void EditAndSave(String fileName) {
Bitmap b = new Bitmap(fileName);
/**
* Edit bitmap b... draw stuff on it...
**/
b.Save(fileName); //<---------Error right here
b.Dispose();
}
My code is similar to the above code. When i try to save the file i just opened, it won’t work. When i try saving it with a different path, it works fine. Could it be that the file is already open in my program so it cannot be written to? I’m very confused.
You are correct in that it is locked by your program and therefore you can’t write to it. It’s explained on the msdn-page for the Bitmap class (http://msdn.microsoft.com/en-us/library/3135s427.aspx).
One way around this (from the top of my head, might be easier ways though) would be to cache image in a memorystream first and load it from there thus being able to close the file lock.