• Advertisement
Sign in to follow this  
  • entries
    135
  • comments
    130
  • views
    52547

.Net 2.0 bug?

Sign in to follow this  

284 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.
Sign in to follow this  


0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement