public void UpdateInfomation(string infomation){
Texture2D texture2d = new Texture2D(1, 1);
texture2d.LoadImage(ReadPNG(infomation));
gameObject.GetComponent<Image>().sprite= Sprite.Create(texture2d, new Rect(0, 0, texture2d.width, texture2d.height), new Vector2(0, 0));
}
/// <summary>
/// 根据图片路径返回图片的字节流byte[]
/// </summary>
/// <param name="imagePath"></param>
/// <returns>返回的字节流</returns>
public static byte[] ReadPNG(string path)
{
FileStream fileStream = new FileStream(path, FileMode.Open, System.IO.FileAccess.Read);
fileStream.Seek(0, SeekOrigin.Begin);
byte[] binary = new byte[fileStream.Length]; //创建文件长度的buffer
fileStream.Read(binary, 0, (int)fileStream.Length);
fileStream.Close();
fileStream.Dispose();
fileStream = null;
return binary;
}
unity3d读取图片文件绘制在UIImage上
最新推荐文章于 2024-09-12 23:24:37 发布