Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.
This repository was archived by the owner on Apr 19, 2026. It is now read-only.

Impossible to take a picture with a good resolution using the font facing camera. #19

Open

Description

@saiimons

When setting a resolution in the preview, such as 1280x960 on a Nexus 5, the output resolution is 320x240.

The camera is set up this way:

        mCameraSource = new CameraSource.Builder(context, detector)
                .setRequestedPreviewSize(1280, 960)
                .setFacing(CameraSource.CAMERA_FACING_FRONT)
                .setRequestedFps(30.0f)
                .build();

And the picture is taken this way:

                mCameraSource.takePicture(null, new CameraSource.PictureCallback() {
                    @Override
                    public void onPictureTaken(byte[] bytes) {
                        Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
                        Log.d("BITMAP", bmp.getWidth() + "x" + bmp.getHeight());
                    }
                });

You can find the modified sample code to help reproduce the issue here

Activity

  1. pm0733464 commented on Aug 31, 2015

    @pm0733464
    Contributor

    The tricky thing about choosing the camera resolution is that the aspect ratio of the preview needs to be about the same as the aspect ratio of the picture, otherwise you'll end up with a distorted preview image. My guess is that the only supported preview/picture sizes that are close enough in aspect ratio for the Nexus 5 front facing camera hardware is 320x240 (preview) and 320x240 (picture).

    It's possible that the code is too conservative about how different the preview vs. picture aspect ratios can be. I'd suggest printing out the sizes from the code below and seeing if there is a preview / picture size pair of about the same aspect ratio that you think it should be using, but is not. Let me know if this is the case.

    You can see what the supported preview sizes and picture sizes are for the Nexus 5 like this:

    List<android.hardware.Camera.Size> supportedPreviewSizes =
            parameters.getSupportedPreviewSizes();
    List<android.hardware.Camera.Size> supportedPictureSizes =
            parameters.getSupportedPictureSizes();
    
  2. saiimons commented on Aug 31, 2015

    @saiimons
    Author

    Supported picture sizes :
    capture

  3. saiimons commented on Aug 31, 2015

    @saiimons
    Author

    Supported preview sizes :
    image

  4. pm0733464 commented on Aug 31, 2015

    @pm0733464
    Contributor

    Sorry, that seems to be a bug in CameraSource. We will take a look.

  5. saiimons commented on Aug 31, 2015

    @saiimons
    Author

    Thanks !

  6. fusion44 commented on Sep 2, 2015

    @fusion44

    I'm also running into this problem. CameraSource.takePicure results in an image with size 1280 x 720 on my Nexus 6 but my Nexus 9 returns an image with size 320 x 1xx (I don't have the exact resolution at hand but its waaay to small)

    Thanks!

  7. Syzygy2048 commented on Sep 16, 2015

    @Syzygy2048

    My Nexus 6 also takes images with a resolution of 240 x 320 (portrait) from both the front and the back facing camera. Same issue with the back facing camera.

  8. Syzygy2048 commented on Sep 21, 2015

    @Syzygy2048

    I managed to hack together a quick fix/hack.
    If you access the Camera object via reflection you can simply do getParameters(), modify them and set them again. I hope this helps you until a fixed version comes out

  9. claywilkinson commented on Sep 27, 2015

    @claywilkinson
    Contributor

    @Syzygy2048 - the CameraSource source code has been included with the barcode reader sample, so you can use it directly vs. using reflection.

  10. pm0733464 commented on Sep 28, 2015

    @pm0733464
    Contributor

    @saiimons The open source version of CameraSource (see above) includes a fix for selecting the resolution. By default, this will select the highest resolution for taking the picture (that also matches the preview aspect ratio).

    Note that the current Google Play Services version of CameraSource does not yet have this fix, but that will be corrected in a future release.

  11. pm0733464 commented on Dec 21, 2015

    @pm0733464
    Contributor

    Update:
    The CameraSource in Google Play Services 8.4 nows select the highest resolution for taking a picture.

  12. urlAkash commented on Dec 29, 2015

    @urlAkash

    @pm0733464 Can You Provide us link!!
    And how to update it into existing code

  13. pm0733464 commented on Dec 30, 2015

    @pm0733464
    Contributor

    No changes to your code are required. Taking a picture with CameraSource in Google Play Services 8.4 will automatically use the highest resolution that the camera supports (which is same aspect ratio of the preview image).

  14. diedel commented on Jul 7, 2017

    @diedel

    I've set setRequestedPreviewSize(640, 480) to cameraSource and I've checked the supportedPreviewSizes and supportedPictureSizes of both the front and back cameras: the 640x480 is supported. Nevertheless I always receive pictures of size 2576x1932...
    The problem is that I need low resolution to pass to the Face Detector as it is very slow with that high resolutions.

  15. diedel commented on Jul 10, 2017

    @diedel

    Well, I analyzed in depth the code and, as you say, it selects the picture size of high resolution available, although the preview size is 640x480.
    Then, if I want a picture size of 640x480, what can I do? Scaling down the picture maybe, in CameraSource.PictureCallback?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions