【发布时间】:2018-04-08 18:15:36
【问题描述】:
我正在使用 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?获取图像的最佳情况是哪种情况适合获取连续图像。
【问题讨论】:
标签: android android-camera2 image-reader