我正在使用 Camera2 API 连续拍照并且工作正常,在这里我可以使用以下代码保存捕获的图像:
ImageReader.OnImageAvailableListener readerListener = new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
Image image = null;
try {
// image = reader.acquireLatestImage();
image = reader.acquireNextImage();
ByteBuffer buffer = image.getPlanes()[0].getBuffer();
byte[] bytes = new byte[buffer.capacity()];
buffer.get(bytes);
save(bytes);
} catch (FileNotFoundException e) {
logFile.writeCrashLog(TAG + ": " + e.toString());
hideProgressDialog();
} catch (IOException e) {
logFile.writeCrashLog(TAG + ": " + e.toString());
hideProgressDialog();
} catch (Exception e) {
logFile.writeCrashLog(TAG + ": " + e.toString());
hideProgressDialog();
} finally {
if (image != null) {
image.close();
}
}
}
private void save(byte[] bytes) throws IOException {
OutputStream output = null;
try {
output = new FileOutputStream(AndroidCameraApiActivity.this.file);
output.write(bytes);
} catch (Exception e) {
logFile.writeCrashLog(TAG + ": " + e.toString());
hideProgressDialog();
} finally {
if (null != output) {
output.close();
}
}
}
};
在这里我想知道通过acquireLatestImage或acquireNextImage获取图像的最佳情况是什么?适合获得连续图像。