我想将图像流(最好是 30fps)保存到设备。我遇到了这个post .
如何使用 cameraX
将图像转储为 YUV_420_888
格式,而不将其编码为 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();
}
});
}
});
最佳答案
How do I dump images in YUV_420_888 format using cameraX without encoding it as JPEG?
您可以使用 ImageCapture.takePicture()
的另一个版本,它返回 YUV_420_888 格式的内存图像 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
}
})
I'll be glad I could any direction in saving burst of images.
连拍图像是以一定速率连续拍摄的图像。如何在应用程序中实现它取决于您想要的用户体验,它可以通过单击按钮或长按来触发。最主要的是您必须多次调用 ImageCapture.takePicture()
,您可以使用 Handler.postDelayed(Runnable, Long)
等 API 来控制图像捕获率。 .
关于java - Android相机应用程序使用CameraX将图像保存为YUV_420_888格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62373908/