System.Drawing.Imaging performance fix in .NET 1.1 SP1

A few months ago I encountered a significant performance problem with System.Drawing.Imaging.

I found that by using the new Method performance was 93x faster (on average) for loading jpegs.

You can download the update here:

Specifically, this update adds a new method to System.Drawing.Imaging:

System.Drawing.Image.FromStream(Stream stream, bool useICM, bool validateImageData)

This is essentially a new signature for an existing method:

System.Drawing.Image.FromStream(Stream stream, bool useICM)

As you can see, validateImageData is a new parameter. Setting it to true is the default behavior that we have today (essentially the same as calling FromStream(Stream stream, bool useICM)).

So I made a change to my application. Before my code looked like this:

using (Image photo = Image.FromFile(this.fileInfo.FullName, true))
//do stuff

So I changed it to:

using (FileStream fs = new FileStream(this.fileInfo.FullName, FileMode.Open, FileAccess.ReadWrite))
using (Image photo = Image.FromStream(fs, true, false))
// do stuff

Comments (1)
  1. Skup says:

    I have already written this but it seems it did not arrive…

    This is new method is a really good things for people that only want to read Exif info.

    But dont expect any change if you’re also using the picture’s pixels.

    The speed improvement is only due to the fact that it doesn’t force the entire image to be read when the file is open.

    If you really need the pixels, the loading is only delayed to the point you access the image data.

Comments are closed.

Skip to main content