User967840515 posted
Image.Save and Image.FromFile seem to both have massive bugs. You are better off doing it yourself.
For this problem in Image.FromFile, use your own FileStream from File.OpenRead, and then use Image.FromStream.
public static Image LoadImage(string fileName)
{
using (FileStream file = File.OpenRead(fileName))
return Image.FromStream(file);
}
For this problem in Image.Save, create a new Bitmap with the correct height, width and pixel format then create a Graphics object from that, draw the original image onto it and save that one.
public static void SaveImage(Image image, string fileName, ImageFormat format)
{
using (Bitmap savingImage = new Bitmap(image.Width, image.Height, image.PixelFormat))
{
using (Graphics g = Graphics.FromImage(savingImage))
g.DrawImage(image, new Point(0, 0));
savingImage.Save(fileName, format);
}
}
I think that these bugs are both something to do with memory allocation in GDI+. They seem to take a while to occur but then once they start happening, the only way I can find to stop them (without changing the code to what I have said) seems to be to restart
the machine.
I've never had any problems with GetThumbnailImage itself and I assume that the solution in the other post only helps because it is not saving the original image.