I need to set the path for saving images using Android app and IOS with UNITY

My actual code is:

function Update() { 
    if(Input.GetMouseButtonDown(0)) {
       Debug.Log("foto");
       Application.CaptureScreenshot(Application.dataPath + "Screenshot.png");
    }
}

I need a way to display each photo for this function.

Thank!

+5
source share
4 answers

You can save the files in Application.persistentDataPath . Unity apps do not have write permission on Application.dataPathAndroid or iOS devices.

Also, be sure to join the path and folder name with a slash:

Application.CaptureScreenshot(Application.persistentDataPath + "/Screenshot.png");
+1
source

Application.persistentDataPath IOS /mnt/android/data/application-bundle-identifier/ android.

Application.CaptureScreenshot put, , "" IOS, android.

, .

0
static function CaptureScreen(){
var filename;
var name :String = GuiScript.stringToEdit;
var allowedScreenshots:int=1000;
for(var i = 0; i <= allowedScreenshots; i++)
    {

        if(Application.platform == RuntimePlatform.Android){
            filename = "/mnt/sdcard/Android/data/com.xxxx.Test01/files/" + name + i + ".png";
        } else {            
            filename =  name + i + ".png";
        }
        if(!System.IO.File.Exists(filename))
        {
            Application.CaptureScreenshot(name + i + ".png" );
            print("ScreenDUMP made!");
            print(i);
            print(name);

            return;
        }
        else
        {
            print("filename already exists");
            print(i);
        }
    }
}
0

3 - Unity3D: Application.CaptureScreenshot, Texture2D.ReadPixels RenderTexture.

: Application.CaptureScreenshot. , , . Application.persistentDataPath Application.dataPath + "/../", . , - . , , . , Coroutine, , , -.

, , - :

bool creatingFile = false;
string fileName = "Screenshot.png"
function Update() { 
    if(Input.GetMouseButtonDown(0)) {
        Application.CaptureScreenshot(fileName);
        creatingFile = true;
    }
    if (creatingFile) {
        string origin = System.IO.Path.Combine(Application.persistentDataPath, fileName);
        string destination = "/sdcard/ScreenCapture/" + fileName; // could be anything
        if (System.IO.File.Exists(origin)) {
            System.IO.File.Move(origin, destination);
            creatingFile = false;
        }
    }
}
0

All Articles