2

I'm using Shell32 to get the Width, Height and the resolution of an Jpg image. I use GetDetailsOf to get these values. That works fine and fast, but after I want to use multi-threading I still see the same performance with 1 or 8 threads.

Is there a threadsafe way to get this information out of the .Net File object?

Thanks, Evert-Jan

With thanks to Tamás F, I used the next code, which is at least 4 times faster:

    public void GetJpegImageSizeAndRes(string filename, out int width, out int height, out float res)
    {
        using (var sr = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read))
        {
            var sz = Image.FromStream(sr, false, false).Size;
            res = Image.FromStream(sr, false, false).HorizontalResolution;
            width= sz.Width;
            height = sz.Height;
        }
    }

Thanks everyone, Evert-Jan

  • __If__ IO is the limit more threads won't help. Maybe you should show us some code..? – TaW Dec 24 '15 at 14:42
  • 1
    This might help: [http://stackoverflow.com/questions/552467/how-do-i-reliably-get-an-image-dimensions-in-net-without-loading-the-image](http://stackoverflow.com/questions/552467/how-do-i-reliably-get-an-image-dimensions-in-net-without-loading-the-image) – Tamás F Dec 24 '15 at 15:24
  • While this sounds promising I wonder why I don't see anything about not loading the full image in the docs..?? – TaW Dec 24 '15 at 21:10

1 Answers1

1

i don´t think you improve the performance of one call of the GetDetailsOf-function. Multithreading could help, when you execute this function for multiple files, or parallel to other tasks.

edit: maybe PLinq helps to improve the loop by using multithreading.

user3104267
  • 190
  • 2
  • 10