我正在下载几张图片,以更改Android的360张照片(每张5760 x 2880 px)。当我更改第20张图像时,应用程序意外关闭。有人可以帮助我,我使用以下代码。
我需要将照片放在Application.persistentDataPath中。
第一个代码
UnityWebRequest wr = new UnityWebRequest("file://" + Application.persistentDataPath + "/" + point.gameObject.name + ".jpg");
DownloadHandlerTexture texDl = new DownloadHandlerTexture(true);
wr.downloadHandler = texDl;
yield return wr.SendWebRequest();
if (!(wr.isNetworkError || wr.isHttpError))
{
Texture2D t = texDl.texture;
mainApp.mainView.photoApartment.GetComponent<Renderer>().material.mainTexture = t;
}
我也使用这个。
var fileName = Application.persistentDataPath + "/" + point.gameObject.name + ".jpg";
var bytes = File.ReadAllBytes(fileName);
var texture = new Texture2D(6080, 3040, TextureFormat.RGBA32, false);
texture.LoadImage(bytes);
mainApp.mainView.photoApartment.GetComponent<Renderer>().material.mainTexture = texture;
mainApp.mainView.photoApartment.GetComponent<Renderer>().material.mainTexture = Resources.Load<Texture2D>("Textures/" + point.gameObject.name); ;