unity加載本地文件圖片並顯示在ugui上(外部文件)縮略圖


代碼如下:

Texture2D tempImage;
RawImage image;
void test()
{
image=localDataObj.transform.GetChild(2).GetComponent<RawImage>()

    StartCoroutine(LoadImage(texturePath ,image));


} IEnumerator LoadImage(
string path, RawImage image) { string filePath = "file://" + 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;
       image.SetNativeSize();
     }
}

 

//圖片等於原圖大小,如果相等大縮放,就在顯示圖片的物體上加一個父物體
       ,更改父物體的 scale

 

 

 

 

 如果想做成手機上那種縮略圖只取其中一部分圖片,就在父物體panel上加上遮罩,Mask

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM