Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Wrong Image Width and Height from smartphone camera pics

Discussion in 'Scripting' started by marck_ozz, Dec 22, 2022.

  1. marck_ozz

    marck_ozz

    Joined:
    Nov 30, 2018
    Posts:
    107
    Hello all,

    I'm building a game for UWP and Windows Standalone in wich the user can upload an image to interact with and I just found a weird behaviour with the pics that comes straight from smartphones (at least samsung that is the one I own) when I read the Width(W) and Height(H)

    I'm using:

    Code (CSharp):
    1. Windows.Storage.FileProperties.ImageProperties imageProperties = await file.Properties.GetImagePropertiesAsync();
    2.  
    3.                                     picWidth = Convert.ToInt32(imageProperties.Width);
    4.                                     picHeight = Convert.ToInt32(imageProperties.Height);
    to get the W and H in UWP

    and for Standalone:

    Code (CSharp):
    1. using (var image = System.Drawing.Image.FromStream(fileStream, false, false))
    2.                 {
    3.                     picHeight = image.Height;
    4.                     picWidth = image.Width;
    5.                 }
    both of them give the same result but in the images that comes from my Note9 the W and H comes inverted.

    In the Pic's Windows Properties the W and H are correct.

    My Questions:
    1.- Is there a metoth to Get the W and H as the Windows Properties shows
    2.- Is there a way to detect or handle pics from smartphones,

    With the UWP metoth I can get much more information about the Pic like orientation and with this info I can invert in the code but in the Standalone code I can't find something like this.

    Using:
    UNITY 2020.3.3F1
    Windows 10

    Notes:
    * In other windows apps (Photoshop, Photos, Paint) the Pics are shown in correct way
    * With the UWP metoth I can get much more information about the Pic, like its orientation, and with this info I can invert the W&H in the code, but for the Standalone code I can't find something like this.
    * If I export or save the same Pics from the mentioned apps the issue is gone.
     
  2. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
  3. AnimalMan

    AnimalMan

    Joined:
    Apr 1, 2018
    Posts:
    1,164
    My mistake to get the dimensions of an image file there is no other way to get it aside decoding the image file. It’s the first few lines of the image once decoded. It’s required to format the reconstruction of the colour data
     
  4. marck_ozz

    marck_ozz

    Joined:
    Nov 30, 2018
    Posts:
    107
    Hello @AnimalMan , thanks for your answer

    Yes, This is related to the Screen size

    I ended up by give the user an option to flip the texture, something like this, maybe is what you mean? because after try different approachs I think that maybe I can have the same problem with pics coming from different devices and manufacturers so this could be not a workaround but the solution to my problem.

    I'll let the Question open because I'm still interested on how to the see the properties as the "Properties Windows"