• entries
135
130
• views
52602

# .Net 2.0 bug?

300 views

I'm currently updating EasyShots a bit, and in doing so I added a new feature. I now allow images to be dragged into EasyShots, once you do, you can manage them, edit, send them and everything that EasyShots lets you do. It worked great, that is until I tried to drag an animated GIF into it.

Dragging the GIF into it wasn't a problem, when I went into edit mode the program threw an exception deep within .Net code, particularily inside the code responsible for switching the GIF's frames.

So after a while of debugging, I came across this piece of code:

FileStream fs = File.Open(mImageFilename, FileMode.Open, FileAccess.Read, FileShare.Read);mBmp = new Bitmap(fs);fs.Close();

So, I thought, could it be possible that in creating the bitmap in that way I lose valuable information?

I replaced that code with this:

mBmp = (Bitmap)Bitmap.FromFile(mImageFilename);

and this worked. So I wonder if it's a bug, or perhaps it's documented somewhere in MSDN (I didn't look) that creating a bitmap from a stream does not guarantee the same results as using the Bitmap class to load the image directly.

But nothing is free... the second approach may fix animated GIFs, but it appears to leave my file open, so when I try to update it, I get an exception that says "Unable to write file, another progress is using the file".

So I guess it's actually two bugs, first using streams to open files loses a GIF's structure, and using Bitmap.FromFile does not close the file after itself.

There are no comments to display.

## Create an account

Register a new account