string url = "https://upload-images.jianshu.io/upload_images/19776427-4be4c0f5c6466dc8.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
public RawImage img;
string LocalUrl = "";
WWW w1;
// WWW w;//网络请求对象
private bool downloadOK;
[System.Obsolete]
void Start()
{
//开启携程
StartCoroutine(GetImage(url));
}
[System.Obsolete]
IEnumerator GetImage(string url)
{
w = new WWW(url);
yield return w;//返回数据(1.成功 2、失败 3.下载完成)
if (w.error ==null||w.progress ==1||w.isDone==true)//所有的问题都不存在
{
//将下载的图片赋值
img.texture = w.texture;
//存储到本地
}
}
public void SaveImage()
{
byte[] date = (img.texture as Texture2D).EncodeToPNG();//转换图片为二进制byte[](0,1)
File.WriteAllBytes(Application.streamingAssetsPath + "/1.png", date);//存储图片的二进制到本地文件夹
LocalUrl = "file://"+Application.streamingAssetsPath + "1.png";
Debug.Log(LocalUrl);
PlayerPrefs.SetString("local", LocalUrl);//保存资源路径
}
string url = "https://upload-images.jianshu.io/upload_images/19776427-4be4c0f5c6466dc8.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
public RawImage img;
string LocalUrl = "";
WWW w1;
WWW w;//网络请求对象
private bool downloadOK;
[System.Obsolete]
void Start()
{
LocalUrl = PlayerPrefs.GetString("Local");
//加载本地存储的照片
if (LocalUrl != null)
{
Debug.Log("本地加载");
StartCoroutine(GetImage(LocalUrl));//开启本地加载(Get)
}
else
{
Debug.Log("网络加载");
//开启携程
StartCoroutine(GetImage(url));
}
}
[System.Obsolete]
IEnumerator GetImage(string url)
{
w = new WWW(url);
yield return w;//返回数据(1.成功 2、失败 3.下载完成)
if (w.error ==null||w.progress ==1||w.isDone==true)//所有的问题都不存在
{//将下载的图片赋值
img.texture = w.texture;
//存储到本地
}
}
public void SaveImage()
{
byte[] date = (img.texture as Texture2D).EncodeToPNG();//转换图片为二进制byte[](0,1)
File.WriteAllBytes(Application.streamingAssetsPath + "/1.png", date);//存储图片的二进制到本地文件夹
LocalUrl = "file://"+Application.streamingAssetsPath + "1.png";
Debug.Log(LocalUrl);
PlayerPrefs.SetString("local", LocalUrl);//保存资源路径
}