问题
I'm making an android camera application. My doubt is how do I pass the supported resolutions as parameters to the camera.
So, first I'm getting all the supported resolution sizes:
Size[] sizes = configurationMap.getOutputSizes(ImageFormat.YUV_420_888);
Log.d("test","size:"+sizes.length);
for(Size size : sizes){
Log.d("test", "width: " + size.getWidth() + " height" + size.getHeight());
}
Then I'm configuring the input with one of these sizes.
InputConfiguration inputConfiguration = new InputConfiguration(1920, 1080, ImageFormat.YUV_420_888);
The I'm passing this input to a capture session
cameraDevice.createReprocessableCaptureSession(inputConfiguration, Arrays.asList(previewSurface), new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession cameraCaptureSession) {
try {
cameraCaptureSession.setRepeatingRequest(mCaptureRequestBuilder.build(), null, handler);
} catch (CameraAccessException e) {
e.printStackTrace();
}
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession cameraCaptureSession) {
Toast.makeText(getApplicationContext(),"Camera Preview Failed!!",Toast.LENGTH_SHORT).show();
}
}, null);
And, I'm also getting an
java.lang.IllegalArgumentException: input size 1920x1080 is not valid
error, though this size is supported on my phone camera (from the debug result of getOutputSizes()
).
So, my question is on my approach and where I'm wrong.
回答1:
Don't confuse getOutputSizes(imageFormat) with getInputSizes(imageFormat). Note that you must check separately that the format is supported for input or output.
来源:https://stackoverflow.com/questions/52697534/how-to-configure-the-capture-size-in-camera-2-api