I am trying to work on my Nexus 5x with android Camera2 APIs and I am using googlesamples android-Camera2Basic
My problem is that the JPEG images have too low quality and their size is much smaller that regular images I am taking with my phone camera app.
According to google documents there should be a key JPEG_QUALITY both in CaptureRequest and in CaptureResult:
JPEG_QUALITY
Added in API level 21
Key JPEG_QUALITY
Compression quality of the final JPEG image.
85-95 is typical usage range.
Range of valid values:
1-100; larger is higher quality
This key is available on all devices.
However when I ask for the available keys, JPEG_QUALITY key is not available so I don't how to know what is my current JPEG compression quallity used and how I can change it.
The code I did inside:
CameraCaptureSession.CaptureCallback CaptureCallback
= new CameraCaptureSession.CaptureCallback() {
@Override
public void onCaptureCompleted(@NonNull CameraCaptureSession session,
@NonNull CaptureRequest request,
@NonNull TotalCaptureResult result) {
//_TEST_DEBUG
List<CaptureRequest.Key<?>> requestKeys = request.getKeys();
List<CaptureResult.Key<?>> resultKeys = result.getKeys();
requestKeys & resultKeys have many keys including JPEG_ORIENTATION but not the JPEG_QUALITY key.
Any idea what am I doing wrong?
Why can't I find how to change JPEG compression quality?
Thanks, Guy
I achieved increasing the JPEG quality by adding it as a key to the CaptureRequest.Builder in the googlesamples android-Camera2Basic with a Tesco Hudl 2 Tablet on Android 5.1 Lollipop.
The JPEG quality is set in the captureStillPicture() method in the Camer2BasicFragment like so:
// This is the CaptureRequest.Builder that we use to take a picture.
final CaptureRequest.Builder captureBuilder =
mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);
captureBuilder.addTarget(mImageReader.getSurface());
//Set the JPEG quality here like so
captureBuilder.set(CaptureRequest.JPEG_QUALITY, (byte)90);
I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With