问题遇到的现象和发生背景
我有一张图是先下载到streamingassets下的,然后本地读取赋值给Image
然后现在出现了这么一个问题
本来应该是白色区域的边缘,结果出现了蓝色,放大看是这样的
这张图的本地资源没有问题,我把streamingassets下的那张原图直接放unity里当texture用也没有问题,不知道为什么会出现这种现象
用代码块功能插入代码,请勿粘贴截图
//本地读取图片的方法
IEnumerator GetLocalTexture(string url, long size, Action<Texture2D> 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的这个流程的前提下,让图片正常显示