unity3d读取图片文件绘制在UIImage上

  public void UpdateInfomation(string infomation){
	Texture2D texture2d = new Texture2D(1, 1);  
 	texture2d.LoadImage(ReadPNG(infomation));
	gameObject.GetComponent().sprite= Sprite.Create(texture2d, new Rect(0, 0, texture2d.width, texture2d.height), new Vector2(0, 0));
	}
    ///   
    /// 根据图片路径返回图片的字节流byte[]  
    ///   
    ///   
    /// 返回的字节流  
    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)