You can read the image in the image window without blocking it, as shown below.
Image img; string file = @"d:\a.jpg"; using (Bitmap bmp = new Bitmap(file)) { img = new Bitmap(bmp); current_pic.Image = img; } if (File.Exists(file)) { File.Delete(file); current_pic.Image.Save(file, ImageFormat.Jpeg); } else current_pic.Image.Save(file, ImageFormat.Jpeg);
I updated the code to support the save operation.
While the previous code supported deletion even after linking to images. The stream was closed, and this, when saved, led to a GDI + error.
Updated code meets all your requirements as follows
- Permission to delete a file when connecting images
- Saving an Image Using the Image Property in a Picturebox Control
source share