I'm trying to apply Camera2 api to take a picture. I got right result on Android 6.0.1
and 5.1.1
But not 5.0
.
I have no idea why.
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraDevice.getId());
Size[] jpegSizes = null;
if (characteristics != null) {
jpegSizes = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP).getOutputSizes(ImageFormat.JPEG);
}
if (jpegSizes != null && 0 < jpegSizes.length) {
width = jpegSizes[0].getWidth();
height = jpegSizes[0].getHeight();
Log.i("jpegSizes width : ", String.valueOf(width));
Log.i("jpegSizes height : ", String.valueOf(height));
}
ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);
List<Surface> outputSurfaces = new ArrayList<Surface>(2);
outputSurfaces.add(reader.getSurface());
outputSurfaces.add(new Surface(new SurfaceTexture(10)));
final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE); // TEMPLATE_VIDEO_SNAPSHOT
captureBuilder.addTarget(reader.getSurface());
captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);
And those are the sizes in jpegSizes array.
I/takepic w :: 5312 h : 2988
I/takepic w :: 3984 h : 2988
I/takepic w :: 3264 h : 2448
I/takepic w :: 3264 h : 1836
I/takepic w :: 2560 h : 1920
I/takepic w :: 2048 h : 1152
I/takepic w :: 1920 h : 1080
I/takepic w :: 1280 h : 960
I/takepic w :: 1280 h : 720
I/takepic w :: 800 h : 480
I/takepic w :: 640 h : 480
I have tried all of them but always get this error:
E/CameraDevice-0-LE: Surface with size (w=1, h=1) and format 0x1 is not valid, size not in valid set: [1920x1080, 1440x1080, 1280x720, 1056x864, 960x720, 800x480, 720x480, 640x480, 352x288, 320x240, 176x144]
W/CameraDevice-JV-0: Stream configuration failed
E/CameraCaptureSession: Session 0: Failed to create capture session; configuration failed
Please get me any solution.