Home > Mobile >  Wrong image width and height when read it with C#
Wrong image width and height when read it with C#

Time:12-29

I've got a strange problem. There is an Image properties in Windows

We need to keep in mind dimensions of this picture: Width is 3000px and Height is 4000px. It looks correct because image is portret.

Then lets try to read it with C#:

private static void TestImage()
{
    using (FileStream file1 = new FileStream("DSC_2446.JPG", FileMode.Open))
    {                
        Console.WriteLine("DSC_2446.JPG :");
        using (var img1 = System.Drawing.Image.FromStream(file1))
        {
            Console.WriteLine($" Width = {img1.Width}");
            Console.WriteLine($" Height = {img1.Height}");
        } 
    }                

    Console.Read();
}

And in results we see some magic!!!

Magic results

So I've got completely wrong values. Values are switched between properties. Does someone know why it can happens and how to detect/fix this behavior?

CodePudding user response:

The problem is the EXIF version. You can use this site to get the real data enter image description here

Also according to this enter image description here

  • Related