开发者社区> 问答> 正文

Unity3D如何从iPhone下载图片?

JastinBall
我用iOS Unity插件给Unity发送了图像路径。在Unity中,我尝试着用收到的路径获取图片(我不知道如何把iPhone的图片发送到Unity)。问题是:我还没能获得图片。WWW Error: The requested URL was not found on this server. (WWW错误:服务器中无法找到请求的URL)

//Tried both "file:///..." and "file://..."
string path = "file://var/mobile/Applications/173DE26D-4C0E-4DF7-9DC6-9CBB7D4FC954/Documents/Images/image.png"

Texture texture;

IEnumerator WaitForRequest(WWW www) {
    yield return www;

    if (www.error == null) {
        texture = www.texture;
    }    
}

void Start() {
    WWW www = new WWW(path);
    StartCoroutine(WaitForRequest(www));
}

展开
收起
a123456678 2016-07-20 17:46:52 2219 0
1 条回答
写回答
取消 提交回答
  • Calvin:
    确保文件是正在被使用着的:

    System.IO.File.Exists("/var/mobile/Applications/173DE26D-4C0E-4DF7-9DC6-9CBB7D4FC954/Documents/Images/image.png")
    因为你的代码看上去是正确的。
    还有,不应写死路径,你应该使用Application.persistentDataPath。

    string path = "file://" + System.IO.Path.Combine(Application.persistentDataPath, "Images/image.png");
    顺便说一句,绝对文件URL应该始终以file:///开始。

    2019-07-17 19:59:08
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载