我正在使用 camera2 API 我有兴趣从字节数组中获取 RGB 值实际上是 RGB 值的平均值当从 ByteBuffer 收集字节数组并使用 FileOutputStream.write(bytes) 写入文件时,我可以从这部分得到它
这是我的代码:
ByteBuffer byteBuffer = mImage.getPlanes()[0].getBuffer();
byte[] bytes = new byte[byteBuffer.remaining()];
byteBuffer.get(bytes);
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(mImageFile);
fileOutputStream.write(bytes);
}
catch (FileNotFoundException e) {
// TODO Auto-generated catch block e.printStackTrace(); } catch
(IOException e) {
// TODO Auto-generated catch block e.printStackTrace();
}
finally {
mImage.close();
try {
fileOutputStream.close();
}
catch (IOException e) { // TODO Auto-generated catch block
e.printStackTrace();
}
}