sevenPixels

读取指定路径图片

  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;
    }

 

posted on 2019-06-21 09:42  sevenPixels  阅读(210)  评论(0编辑  收藏  举报

导航