在unity裏面創建StreamingAssets文件夾,
參數是路徑,下面是圖片的尺寸
private Sprite LoadImage(string path)
{
Texture2D texture = new Texture2D(701, 395);
using (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);
texture.LoadImage(bytes);
}
return Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
}