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

 
posted @ 2020-04-10 10:26  WalkingSnail  阅读(2419)  评论(0)    收藏  举报