using System.IO;
using UnityEngine;
using UnityEngine.UI;
public class LoadPicture : MonoBehaviour
{
void LoadPicByIo(RawImage raw,int index)
{
FileStream fileStream = new FileStream(Application.dataPath + "/" + index + ".png", 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();
fileStream = null;
int width = 1920;
int height = 1080;
Texture2D tex = new Texture2D(width, height);
tex.LoadImage(bytes);
raw.texture = tex;
}
void LoadPicByIo(Image img, int index)
{
FileStream fileStream = new FileStream(Application.dataPath + "/" + index + ".png", 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();
fileStream = null;
int width = 1920;
int height = 1080;
Texture2D tex = new Texture2D(width, height);
tex.LoadImage(bytes);
img.sprite = Sprite.Create(tex, new Rect(0, 0, 1920, 1080), new Vector2(0, 0));
}
}
|