I get a photo from the phone camera and paste it into the frame (UI Image). If you left the application and came back again, you need to save the picture. To save using Asset Easy Save.

Code to save:

public void OnApplicationQuit() { im1 = GameObject.FindGameObjectsWithTag("um1"); for (int i = 0; i < im1.Length; i++) { ES2.SaveImage(im1[i].GetComponent<Image>().sprite.texture, "fileDirectory" + i + ".png"); } } 

Download Code:

 void Start() { fileDirectory = Application.persistentDataPath; if (Directory.Exists("fileDirectory")) { im1 = GameObject.FindGameObjectsWithTag("um1"); for (int i = 0; i < im1.Length; i++) { Texture2D tyuio = ES2.LoadImage("fileDirectory" + i + ".png"); Sprite imga = SpriteFromTex2D(tyuio); im1[i].GetComponent<Image>().sprite = imga; } } 

Everything works under Windows, but not under Android, what could be the problem?

    2 answers 2

    The problem may be in the path fileDirectory = Application.persistentDataPath; , in android it is different. Did you debug in android?

      The problem was solved when I decided to see how the OnApplicationQuit () method still works. I used to think that it should be called automatically when the application is closed, but in Unity it works a little differently. The problem was that in Windows it was called automatically, but in Android I didn’t want to. I had to create a separate button and hang OnApplicationQuit () on it. After that, everything worked.