Unity加载图片的两种方式

//WWW加载  
private IEnumerator Load()
    {
		var path= "file:///F:/Loading界面效果图.jpg";// 注意:这里的路径中一定不能有中文,否则加载不出来,注意是路径跟文件名无关.
		WWW www = new WWW(path);
		yield return www;
		if (www != null && string.IsNullOrEmpty(www.error)) ;
		{
			Texture2D texture = www.texture;
			img.texture = texture;
			img.SetNativeSize();
		}
	}``

//IO加载
private void LoadImg()
    {
		FileStream fileStream = new FileStream(Application.streamingAssetsPath + "/Loading界面效果图.jpg", FileMode.Open, FileAccess.Read);
		fileStream.Seek(0, SeekOrigin.Begin);
		byte[] bytes = new byte[fileStream.Length];
		fileStream.Read(bytes, 0, (int)fileStream.Length);
		fileStream.Close();
		fileStream.Dispose();
		fileStream = null;

		Texture2D tex = new Texture2D(1920, 1080);
		tex.LoadImage(bytes);

		img.texture = tex;
    }
//如果通过WWW加载IO的路径什么都加载不出来,原因就是我的路径中有中文符号,具体什么原因不清楚,先记载一下.

你可能感兴趣的:(unity3d)