ios - 图像无法从 ios 设备统一加载
<p><p>我正在使用统一加载保存在设备中的 facebook 个人资料图片。该代码在 Android 中运行良好,但在 IOS 中运行良好。我被这个问题困扰了很多天。所以这是我的代码,请帮助我。</p>
<pre><code>using UnityEngine;
using System.Collections;
using System.IO;
using UnityEngine.UI;
public class UserProfilePicture : MonoBehaviour {
public RawImage profilePicture, testProfile;
private Texture2D texture,text;
void FixedUpdate(){
if (FbSetup.userInfoLoaded) {
if(SPFacebook.instance.userInfo.GetProfileImage(FacebookProfileImageSize.square) != null) {
text = SPFacebook.instance.userInfo.GetProfileImage(FacebookProfileImageSize.square);
}
}
testProfile.texture = text as Texture;
byte[] textureByte = text.EncodeToPNG ();
File.WriteAllBytes (Path.Combine(Application.persistentDataPath,"profilePicture.png"),textureByte);
Debug.Log("Save path: " + Application.persistentDataPath + Path.DirectorySeparatorChar + "profilePicture.png");
if(File.Exists(Application.persistentDataPath + Path.DirectorySeparatorChar + "profilePicture.png")){
Debug.Log("Texture saved");
}
}
void Update(){
StartCoroutine (Control ());
profilePicture.texture = texture as Texture;
}
IEnumerator Control(){
WWW pictureUrl;
pictureUrl = new WWW(System.Uri.EscapeUriString("file://" + Path.Combine(Application.persistentDataPath,"profilePicture.png")));
yield return new WaitForEndOfFrame();
texture = pictureUrl.texture;
Debug.Log("Loaded path: " + Path.Combine(Application.persistentDataPath,"profilePicture.png"));
}
void OnEnable(){
if (GLobal.playAsGuest) {
this.gameObject.SetActive(false);
}
else{
this.gameObject.SetActive(true);
}
}
</code></pre>
<p>感谢您的帮助,谢谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>原来问题出在下面一行。</p>
<pre><code>yield return new WaitForEndOfFrame();
</code></pre>
<p>显然,一帧不足以从磁盘加载文件。你很幸运,在你的安卓设备上已经足够了。所以你应该把那行改成</p>
<pre><code>yield return pictureUrl;
</code></pre>
<p>所以它会等到加载完成。</p></p>
<p style="font-size: 20px;">关于ios - 图像无法从 ios 设备统一加载,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/31175566/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/31175566/
</a>
</p>
页:
[1]