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