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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Why can't I correctly save and load a photo on iPhone 5?

Discussion in 'General Graphics' started by Thejon, Aug 5, 2015.

  1. Thejon

    Thejon

    Joined:
    Nov 12, 2013
    Posts:
    11
    I am using the Etcetera plugin on iOS to load a photo with the photo picker. Initially the texture appears correctly. I then save the photo to disk using Texture2D's EncodeToPNG. When loading the texture again later, the width and height are correct but the contents are stretched due to what I assume is a "pixel" aspect ratio (not picture aspect ratio). This causes the image to appear both cropped and stretched. This problem doesn't occur on iPhone 6. I have no idea how to fix this or where the problem is. Anyone have any ideas or workarounds?
     
  2. Thejon

    Thejon

    Joined:
    Nov 12, 2013
    Posts:
    11
    Not fully tested, but it appears that using the WWW class will work.

    So whereas I was essentially doing this:
    <code>
    Texture2D texture = new Texture2D(2, 2);
    texture.LoadImage(File.ReadAllBytes(filePath));
    return texture;
    </code>
    I can now do this:
    <code>
    string fileUrl = "file://" + filePath;
    WWW www = new WWW(fileUrl);
    yield return www;
    tex = www.texture;
    </code>