Unity读取本地图片

刚接过证件扫描(文通科技)的sdk跟人脸识别活体认证(商汤)的sdk。这些都是会获取摄像头并截取固定区域的突变保存到本地的。

然后客户端这边就需要在本地获取到图片路径并读取转为byte[]类型传输给服务器。

//读取本地图片转byte[]
    public static byte[] ReadTexture(string path)
    {
        Debug.Log(" @ ! the texture path is + !!    " + path);
        FileStream fileStream = new FileStream(path, FileMode.Open, System.IO.FileAccess.Read);

        fileStream.Seek(0, SeekOrigin.Begin);

        byte[] buffer = new byte[fileStream.Length]; //创建文件长度的buffer   
        fileStream.Read(buffer, 0, (int)fileStream.Length);

        fileStream.Close();

        fileStream.Dispose();

        fileStream = null;

        return buffer;
    }

猜你喜欢

转载自blog.csdn.net/qq_37310110/article/details/80910441