我想将图像流(最好是30fps)保存到设备。我碰到了这篇文章。
如何使用cameraX转储YUV_420_888格式的图像而不将其编码为JPEG?
另外,我很高兴能为保存图像的连拍提供任何方向。
到目前为止,我仅在单击按钮时保存图像
findViewById(R.id.capture_button).setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){
File file = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES),
"Image_" + System.currentTimeMillis() + ".jpg");
imageCapture.takePicture(file, new ImageCapture.OnImageSavedListener() {
@Override
public void onImageSaved(@NonNull File file) {
Toast.makeText(CameraCaptureActivity.this, "Photo saved as " + file.getAbsolutePath(), Toast.LENGTH_SHORT).show();
}
@Override
public void onError(@NonNull ImageCapture.ImageCaptureError imageCaptureError, @NonNull String message, @Nullable Throwable cause) {
Toast.makeText(CameraCaptureActivity.this, "Couldn't save photo: " + message, Toast.LENGTH_SHORT).show();
if (cause != null)
cause.printStackTrace();
}
});
}
});
如何使用不带cameraX的YUV_420_888格式的图像转储 编码为JPEG吗?
您可以使用其他版本的ImageCapture.takePicture()
返回YUV_420_888格式的内存图像ImageCapture.takePicture(Executor, OnImageCaptureCallback)
。
ImageCapture.takePicture(Executor, OnImageCaptureCallback)
我很高兴能为保存图像的连拍提供任何方向。
连拍图像是以一定速率接连拍摄的图像。在应用程序中实施方式的方式取决于您希望用户体验如何,可以通过单击一次按钮或长时间单击来触发。最主要的是您必须对imageCapture.takePicture(executor, new ImageCapture.OnImageCapturedCallback() {
@Override
public void onCaptureSuccess (ImageProxy imageProxy) {
// Use the image, then make sure to close it before returning from the method
imageProxy.close()
}
@Override
public void onError (ImageCaptureException exception) {
// Handle the exception however you'd like
}
})
进行多次调用,您可以使用诸如ImageCapture.takePicture()
之类的API来控制图像捕获率。