加载StreamingAssets的图片
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;

public static class LoadImage
{
    public static Sprite Load(string path,int width, int height)
    {
        Texture2D tx = new Texture2D(3840, 2160);
        tx.LoadImage(getImageByte(Application.streamingAssetsPath+"/"+path));
        Sprite sprite = Sprite.Create(tx, new Rect(0, 0, tx.width,tx.height), Vector2.zero);
        return sprite;
    }

    private static byte[] GetImageByte(string imagePath)
    {
        FileStream files = new FileStream(imagePath, FileMode.Open);
        byte[] imgByte = new byte[files.Length];
        files.Read(imgByte, 0, imgByte.Length);
        files.Close();
        return imgByte;
    }

}
上一篇
下一篇