Not getting image from Persistant path in Android using unity3d

元气小坏坏 提交于 2019-12-13 04:32:22

问题


I have a script to take screenshot and save that image and to show that image in a plane.

But not getting that texture.

private string path;

void Start () {
       path = Application.persistentDataPath;
    }

void captureScreeshot(){ 
    Application.CaptureScreenshot(path + "/Screenshot.png");
    alert.text = "saved";
    StartCoroutine(saveScreenshot()); 
    onetimeBool = false;
}
IEnumerator saveScreenshot(){
    WWW imgfile = new WWW("file://" + path+ "/Screenshot.png");
    yield return imgfile;
    if(imgfile.error==null){
       img = new Texture2D(200, 200, TextureFormat.RGB24, false); 
       imgfile.LoadImageIntoTexture(img);
       alert.text = "got image";
        GameObject.Find("plane").renderer.material.mainTexture = img;

    }else{
       print(imgfile.error);
    }
}

Images gets saved.

But I cannot open (load) image in system and android.

Getting error in system :

Couldn't open file /Users/ether/AppData/LocalLow/Company/Project/Screenshot.png

How to get it ???


回答1:


This is because your path is wrong, you should use: application.dataPath, instead of Application.persistentDataPath.



来源:https://stackoverflow.com/questions/17809173/not-getting-image-from-persistant-path-in-android-using-unity3d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!