using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class LoadImage : MonoBehaviour {
    Texture2D tempImage;
    private RawImage RawImageRef;
    // Use this for initialization
    void Start () {
        RawImageRef = gameObject.GetComponent<RawImage>();
        StartCoroutine(OnLoadImage("uploadFile/projectImg/22.jpg", RawImageRef));
    }
    
    // Update is called once per frame
    void Update () {
        
    }
    IEnumerator OnLoadImage(string path, RawImage image)
    {

        string filePath = "file://" + Application.persistentDataPath + "/document/" + path;
        //string filePath = "file://" + "/sdcard/TKData/SaveData/" + "document/" + path;//手机
        WWW www = new WWW(filePath);
        yield return www;
        if (www.error != null)
        {
            Debug.LogError(filePath + www.error);

            image.gameObject.SetActive(false);
        }
        else
        {
            Debug.LogError(filePath);
            image.gameObject.SetActive(true);
            tempImage = www.texture;
            image.texture = tempImage;
        }

    }
}

将图片放入本地指定文件夹即可

unity设置如下

unity+Android+PC加载本地图片

 

相关文章:

  • 2022-12-23
  • 2021-12-12
  • 2021-12-19
  • 2021-11-28
  • 2021-06-22
  • 2021-06-16
  • 2021-07-30
猜你喜欢
  • 2021-12-02
  • 2022-01-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案