1

After I call: cameraSource.takePicture(null, pictureCallback); in the callback:

private CameraSource.PictureCallback pictureCallback = new CameraSource.PictureCallback() {
                @Override
                public void onPictureTaken(byte[] bytes) {
                    try {
        Log.d(DEBUG_TAG, "On picture taken.");
                        if (bytes == null) {
                            return;
                        }
                        Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                        Glide.with(this).load(bitmap).into(capturedImg);
                    }catch (Exception ex){
                        ex.printStackTrace();
                        Log.e("PictureTaken",ex.toString());
                }
            };

When the bitmap is created the resolution is very low (320x240). The camera is capable of taking higher resolution photos. around 1600x1200 from the normal camera app. But using the normal Camera api returns a resolution of 1280x720 for the same camera.

So only using the CameraSource from the Mobile Vision API returns a very low resolution image. But this is not consistent. It returns a high resolution on samsung tablets. But when I used the same code on my Lenovo tab 3, CameraSource returns a very low resolution image. What could be the problem and the possible fix?

V.Bhat
  • 63
  • 10

1 Answers1

0

CameraSource class is open source, at least some version if it, https://github.com/googlesamples/android-vision/blob/master/visionSamples/barcode-reader/app/src/main/java/com/google/android/gms/samples/vision/barcodereader/ui/camera/CameraSource.java. You are free to extend it to set better picture size.

Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
  • Thank you so much for your answer. After going through the CameraSource file I understood that the camera was giving a mPictureSize of 320x240 for a requested size of 1280x1024. I was able to go through the 'validPreviewSizes' and get a clearer mPicture after requesting a resolution of 1280x720. Now, I wonder if this requested resolution will work on all the devices and give a clearer picture. – V.Bhat Jan 12 '18 at 06:44
  • You cannot trust all devices to support 1280x720. You can check supported preview sizes and supported picture sizes, close the camera, and open a CameraSource. – Alex Cohn Jan 12 '18 at 07:29
  • 1
    Thanks, your solution was useful in improving image resolution. I understood the way the camera Selects preview picture sizes from the open sourced class. The problem was that I was setting a previewSize which was just next to the lowest one in the devices list of accepted previewSizes. Changed my preview size to a different value after which. – V.Bhat Jan 31 '18 at 06:14