You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 19, 2026. It is now read-only.
Repository navigation
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
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:
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)
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.
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
@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.
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).
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.
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?
Activity
pm0733464 commentedon Aug 31, 2015
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:
saiimons commentedon Aug 31, 2015
Supported picture sizes :

saiimons commentedon Aug 31, 2015
Supported preview sizes :

pm0733464 commentedon Aug 31, 2015
Sorry, that seems to be a bug in CameraSource. We will take a look.
saiimons commentedon Aug 31, 2015
Thanks !
fusion44 commentedon Sep 2, 2015
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!
Syzygy2048 commentedon Sep 16, 2015
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.
Syzygy2048 commentedon Sep 21, 2015
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
claywilkinson commentedon Sep 27, 2015
@Syzygy2048 - the CameraSource source code has been included with the barcode reader sample, so you can use it directly vs. using reflection.
pm0733464 commentedon Sep 28, 2015
@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.
pm0733464 commentedon Dec 21, 2015
Update:
The CameraSource in Google Play Services 8.4 nows select the highest resolution for taking a picture.
urlAkash commentedon Dec 29, 2015
@pm0733464 Can You Provide us link!!
And how to update it into existing code
pm0733464 commentedon Dec 30, 2015
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).
diedel commentedon Jul 7, 2017
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.
diedel commentedon Jul 10, 2017
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?