/// <summary> /// 以IO方式进行加载 /// </summary> private void LoadByIo(string url,GameObject ImageOBJ) {//创建文件读取流 FileStream fileStream = new FileStream(url, FileMode.Open, FileAccess.Read); //创建文件长度缓冲区 byte[] bytes = new byte[fileStream.Length]; //读取文件 fileStream.Read(bytes, 0, (int)fileStream.Length); //释放文件读取流 fileStream.Close(); //释放本机屏幕资源 fileStream.Dispose(); fileStream = null; //创建Texture int width = 300; int height = 372; Texture2D texture = new Texture2D(width, height); texture.LoadImage(bytes); //创建Sprite Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); ImageOBJ.GetComponent<Image>().sprite = sprite; }
标签:Sprite,fileStream,texture,height,width,Unity,IO,new,加载 From: https://www.cnblogs.com/zqiang0803/p/16805441.html