IO流代码:
void LoadByIO() {
float time = Time.time;
FileStream fs = new FileStream(path, FileMode.Open, FileAccess.Read);
fs.Seek(0, SeekOrigin.Begin);
byte[] bytes = new byte[fs.Length];
fs.Read(bytes, 0, (int)fs.Length);
fs.Close();
fs.Dispose();
fs = null;
Texture2D t = new Texture2D(1,1);
t.LoadImage(bytes);
img.texture = t;
Debug.Log("IO读取图片用时:" + (Time.time-time));
}
WWW代码:
IEnumerator LoadByWWW() {
float time = Time.time;
WWW w = new WWW("file://" + path);
yield return w;
if (string.IsNullOrEmpty(w.error) == false)
{
Debug.Log("error");
}
else {
img1.texture = w.texture;
}
Debug.Log("www读取图片用时:" + (Time.time - time));
}
结果截图: