I'm making an app that adds (draws) some text on an image stored initially in a file. I managed to modify the image and save it in another file, but I'm trying not to create a second file, but store the result in the original file, although when I try to do that, as said in the Microsoft documentation website, that will result in an Exception being thrown (because the Image.Save method does not allow to write in the same file the image was created from). Is there a way to do it properly?
Right now I've made a workaround, saving the modified image into another file, and then I deleting it and changing the name of the second file to the original one.
Here's my code.
Image image = Image.FromFile(originalFile);
Graphics graphics = Graphics.FromImage(image);
...
graphics.DrawString(line, ...);
...
image.Save(newFile);
graphics.Dispose();
image.Dispose();
File.Delete(originalFile);
File.Move(newFile, originalFile);