public static Sprite GetSpriteByIO(string _path)
{
FileStream fileStream = new FileStream(_path, 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();
Texture2D tex = new Texture2D(1, 1);
tex.LoadImage(bytes);
Sprite sp = Sprite.Create(tex, new Rect(0, 0, tex.width, tex.height), new Vector2(0.5f, 0.5f));
sp.name = tex.name;
return sp;
}
来源:https://www.cnblogs.com/SevenPixels/p/11062798.html