Ive managed to get something like this to work in another project but not on my current.
The file locks and cannot be overwritten when saving again even though i dispose of the b bitmap before calling save. Any idea of what i might be doing wrong?
Bitmap b = (Bitmap)Image.FromFile("image.png");
Bitmap bClone = (Bitmap)b.Clone();
// modify bClone here..
b.Dispose();
b = null;
GC.Collect();
bClone.Save("image.png");
The “Clone” method doesn’t do what you want. You can use the Bitmap’s copy constructor instead to create a separate image that contains the same pixels.