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

Save Texture 2d Image to CameraRoll

Discussion in 'iOS and tvOS' started by trunkz, Oct 13, 2014.

  1. trunkz

    trunkz

    Joined:
    Jul 18, 2014
    Posts:
    29
    Hi all,
    I got this problem and i need your help,
    i capture a photo and load it to the texture 2d, so and want to save it to camera Roll but it's doesn't work.
    Here the code :
    Code (CSharp):
    1. private IEnumerator saveScreenshotToIOS ()
    2.     {
    3.         yield return new WaitForEndOfFrame ();
    4.        
    5.         var tex = new Texture2D (Screen.width, (int)(maxVector3.y - minVector3.y), TextureFormat.RGB24, false);
    6.        
    7.         tex.ReadPixels (rec = new Rect (0, Screen.height - (maxVector3.y - minVector3.y), Screen.width, (maxVector3.y - minVector3.y)), 0, 0, false);
    8.        
    9.         var bytes = tex.EncodeToPNG ();
    10.         Destroy (tex);
    11.         var path = Application.persistentDataPath;
    12.         File.WriteAllBytes (path, bytes);
    13.  
    14.        
    15.     }
     
  2. trunkz

    trunkz

    Joined:
    Jul 18, 2014
    Posts:
    29
  3. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,287
    How are you saving to the camera roll? I can see you writing a png into the application. Does that get written?

    Also, rather than waiting 2 hours and then writing 2 characters ("up") into your thread, maybe offer more information about the things you have tried. Maybe you've been looking at the Prime31 plugin, Asset Store, or forum thread by u3dxt?
     
  4. DeveshPandey

    DeveshPandey

    Joined:
    Sep 30, 2012
    Posts:
    221
    pixel_fiend and Graham-Dunnett like this.