读取指定路径图片

  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

猜你喜欢

转载自blog.csdn.net/weixin_33785972/article/details/94448437