Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
« Evil Jag Drivers | Main | Moosaic Takes Shape »
Thursday
Sep212006

But is it a bug?

I noticed a little "foible" of Windows when I was writing my Moosaic program. Windows provides a lovely way that you can load an image into a program. You just go:

Bitmap b = new Bitmap ( filename );

This goes off to the filename and gets you a shiny bitmap which contains your picture. However, it also leaves open the connection to the file, so that if you try to delete the file you get an error saying the file is in use. I don't think that it is. I've just read an image from it, that is all.

This is rather frustrating if you want to reuse a temporary image file. In the end I had to use a stream to read the file, which I could then properly let go of..

StreamReader streamReader = new StreamReader( filename );
Bitmap b = new Bitmap( streamReader.BaseStream );
streamReader.Close();

This is messy, but works in that the file is released. I'm wondering if I've found a bug or a feature...

Reader Comments

There are no comments for this journal entry. To create a new comment, use the form below.

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
All HTML will be escaped. Hyperlinks will be created for URLs automatically.