Hi, I'm writing this little image browser written in C# with a file rename feature. Trouble is that when I try to rename the file that's displayed I get an error with a message that the picture file is being used by a process.
So I thought that I should show you the method that displays the image in a picture box and displays some information about it inside a label.
public void SetPicture(string path){
currentImagePath = path;
pictureBox1.SizeMode =
PictureBoxSizeMode.StretchImage;pictureBox1.Image =
new Bitmap(path); FileInfo fi = new FileInfo(path);label1.Text =
string.Format("{0}x{1}pixels {2}", pictureBox1.Image.Width, pictureBox1.Image.Height, fi.LastWriteTime); this.Text = path;// set window title}
Is the culprit here?
Thanks, Henri
Henri de FeraudyPosted May 4, 2008, 3:12 AM
And one more thing, your solution does allow me to save a backup with the original name.
Henri de FeraudyPosted May 4, 2008, 3:10 AM
Thanks Scott,
I did think of something vaguely along those lines and looked for a Close operation, but could not find one.
It does seem strange that the only way to close is to save, but I'll use that.
Henri
Scott LyslePosted May 4, 2008, 2:17 AM
It must be in the save; the code you provided works. I checked against a hard coded save using your code along with this simple save method:
private void button2_Click(object sender, EventArgs e)
{
try
{
pictureBox1.Image.Save(@"C:\Temp\Junk.jpg");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
}