| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| C-Sharp Programming Post questions, answers, and comments about C#. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Picturebox keeping Image file open?
In my initialisation I have:
Code:
// read the image Image thumbnailImage = Image.FromFile(thumbnailFilename); // put the image in a picturebox PictureBox pb = new PictureBox(); pb.Image = thumbnailImage; Code:
File.Delete(thumbnailFileName); How can I put an Image from a File into a PictureBox, without keeping the file open?
__________________
--- Rob I'm based on a true story, set sometime in the near future. A "Dumb" question, is one that you wished you had asked when you had the chance. --- |
|
#2
|
|||
|
|||
|
Re: Picturebox keeping Image file open?
before
Code:
File.Delete(thumbnailFileName); Code:
pb.Image.Dispose(); |
|
#3
|
||||
|
||||
|
Re: Picturebox keeping Image file open?
Thanks, that fixed it. Infact I had already tried
Code:
pb.Dispose();
__________________
--- Rob I'm based on a true story, set sometime in the near future. A "Dumb" question, is one that you wished you had asked when you had the chance. --- |
|
#4
|
||||
|
||||
|
Re: Picturebox keeping Image file open?
Another way to do this is to open the image from a Stream with a using block.
__________________
Arjay Need a little help with Win32 thread synchronization? Check out the following CG articles and posts: Sharing a thread safe std::queue between threads w/progress bar updating Simple Thread: Part I Simple Thread: Part II Win32 Thread Synchronization, Part I: Overview Win32 Thread Synchronization, Part 2: Helper Classes www.iridyn.com
|
|
#5
|
||||
|
||||
|
Re: Picturebox keeping Image file open?
Using a stream maybe neater. I am in the 'get it working' phase at the moment, I'll try that on my first refactor...
Thanks to both for the ideas.
__________________
--- Rob I'm based on a true story, set sometime in the near future. A "Dumb" question, is one that you wished you had asked when you had the chance. --- |
|
#6
|
||||
|
||||
|
Re: Picturebox keeping Image file open?
I'm still having fun with this. I think my current problem(s) may all be related to the following question:
This works: Code:
Image image;
using (FileStream fs = new FileStream(imageFileName, FileMode.Open))
{
_image = Image.FromStream(fs);
_image.Save(anotherFileName);
}
Code:
Image image;
using (FileStream fs = new FileStream(imageFileName, FileMode.Open))
{
_image = Image.FromStream(fs);
}
_image.Save(anotherFileName); // <-- errors here
How can I get an Image from a file and detach it from everything, so another process can overwrite the original file for example?
__________________
--- Rob I'm based on a true story, set sometime in the near future. A "Dumb" question, is one that you wished you had asked when you had the chance. --- |
|
#7
|
||||
|
||||
|
Re: Picturebox keeping Image file open?
I don't think you can detach it from the file system as such, but you could copy the file to a temporary directory and display the copy to the user. Then the original file should be left open.
__________________
It's not a bug, it's a feature! |
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|