我有一张图是先下载到streamingassets下的,然后本地读取赋值给Image
然后现在出现了这么一个问题
//本地读取图片的方法
IEnumerator GetLocalTexture(string url, long size, Action actionResult)
{
UnityWebRequest www = UnityWebRequestTexture.GetTexture(url);
yield return www.SendWebRequest();
Texture2D myTexture = null;
if (www.isNetworkError || www.isHttpError)
{
// ...
}
else
{
// ...
myTexture = ((DownloadHandlerTexture)www.downloadHandler).texture;
// 加载的图片进行压缩
myTexture.Compress(true);
www.downloadHandler.Dispose();
StartCoroutine(tools.ToDestoryThis());
}
www.Dispose();
if (actionResult != null)
{
if (myTexture != null)
{
actionResult(myTexture);
}
}
}
// 调用加载的方法
HttpRequest.Instance.GetLocalTexture2D(path, size, (texture) =>
{
Sprite spriteFromWeb = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0, 0));
image.sprite = spriteFromWeb;
});
图片边缘颜色不正确
在不改变先下载到streamingassets再加载到image的这个流程的前提下,让图片正常显示
你这样,你先加载texture2d,加载完成后,再进行sprite的转换,而不是现在的直接加载并转换。