0

I have a valid jpeg frame that is taken from a camera:

http://www.developerinabox.com/test.jpg

I'm loading this with the below (example) code:

using System.Net;
using System.Drawing;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {

            WebRequest req = WebRequest.Create("http://www.developerinabox.com/test.jpg");
            req.Timeout = 5000;
            WebResponse resp = null;


            resp = req.GetResponse();
            if (resp != null)
            {
                var s = resp.GetResponseStream();
                if (s != null)
                {
                    Image img = Image.FromStream(s); //<-- Error thrown here
                }
            }


        }
    }
}

In windows XP/Vista/7 this works fine.

In windows 8 it's failing with "generic error in gdi+" I've tried loading it via WPF with the same result.

I can display the image on my windows 8 PC in google chrome but not in IE. It will display in both on windows XP/Vista/7.

I can open it on my Windows 8 box in Fireworks but trying to open it in paint gives me:

"This is not a valid bitmap file, or its format is not currently supported."

Any ideas?

Sean
  • 2,033
  • 2
  • 23
  • 28

1 Answers1

3

Actually, it is an invalid JPEG image but, as you can see, many applications can decode this image seamlessly. This JPEG image has a bogus SOS marker (sorry for the technical information), this Scan header (SOS) says that this image has 1 color component but the Frame header (SOF, which appears before the SOS in the JPEG file structure) claims that it's a 3 components image.

So the Scan header has less information than required but the missing information can be replaced with default values and the JPEG image should be decoded with no issues, which is exactly what is happening. The missing information are the Huffman table indices and default sets of these indices can be assumed based on the JPEG coding type (sequential, progressive or lossless).

Well, it seems that Win8 is stricter when it comes to JPEG decoding. If you are curious you can take a look to this code I uploaded for another JPEG related issue (it's coded in VB.NET) and you can debug it to know where the problem is (you should check JPEG specifications as well).


EDIT: It was a valid JPEG image after all

This JPEG is a baseline multi-scan sequential image (similar to a planar image), not to be confused with a progressive image (which is similar to an interlaced image). So this JPEG has a smaller Scan header because the image is decoded one component at a time. Thus, this file has 3 non-contiguous Scan headers (SOS for 1st component, compressed data, SOS for 2nd component, compressed data,...), and each scan header has information for a single component.
Finally, if the problem was an incomplete or bogus scan header there would be a workaround (you could fix a bogus SOS header) but this is not the case. So you could make a request to the MS guys asking for support for multi-scan sequential JPEG images on Win8 ;-) or use some third-party JPEG decoding library.

Community
  • 1
  • 1
Jigsore
  • 46
  • 1
  • Great - thanks a lot. What did you use to find that out? any idea what i can do to it to get it to display? Unfortunately changing the firmware on the camera isn't an option... – Sean Nov 01 '12 at 05:00
  • Sorry for the late response. I discovered that it's a valid JPEG file. Check my edit... – Jigsore Nov 21 '12 at 10:42