我想将图像流(最好是30fps)保存到设备。我遇到了此post。
如何使用YUV_420_888
以cameraX
格式转储图像而不在JPEG
中进行编码?
此外,如果有人能建议任何方向保存图像连拍,我会很高兴。
到目前为止,我仅通过按钮的onclick
保存图像
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来控制图像捕获率。