0

Currently working on a barcode scanner on xamarin android. I am using the google vision API.

    cameraSource = new CameraSource
        .Builder(this, barcodeDetector)
        .SetRequestedPreviewSize(1920, 1080)
        .Build();

This is the code that i'm using to build the camera view. If i understand correctly, SetRequestedPreviewSize is used to display the camera view on the phone. How can i change the resolution that the camera of the phone is using? I couldn't find any answer sadly.

Urban
  • 585
  • 2
  • 13
  • 28

1 Answers1

3

How can i change the resolution that the camera of the phone is using?

You can get the camera's resolution before initializing the CameraSource:

int numCameras=Camera.getNumberOfCameras();
for (int i=0;i<numCameras;i++)
{
    Camera.CameraInfo cameraInfo=new Camera.CameraInfo();
    Camera.getCameraInfo(i,cameraInfo);
    if (cameraInfo.facing== Camera.CameraInfo.CAMERA_FACING_FRONT)
    {
        Camera camera= Camera.open(i);
        Camera.Parameters cameraParams=camera.getParameters();
        List<Camera.Size> sizes= cameraParams.getSupportedPreviewSizes();
        int width=sizes.get(0).width;
        int height=sizes.get(0).height;
    }
}
Elvis Xia - MSFT
  • 10,801
  • 1
  • 13
  • 24
  • Thanks for the comment! So if i understand this correctly your code is used for getting the current resolution of the camera. And the setRequestedPreviewSize is used for setting the resolution of the camera? Sorry for this question, but it's the first time using this. – Urban May 17 '17 at 06:53
  • [setRequestPreviewSize](https://developers.google.com/android/reference/com/google/android/gms/vision/CameraSource.Builder) is used to set the desired width and height of the camera frames in pixels. And the codes in my answer is used to get the supported preview size of the front Camera. – Elvis Xia - MSFT May 17 '17 at 06:58
  • It's a working solution. You have to set this param inside a frame onLayout() function and CameraSource setRequestedPreviewSize() to get correct camera preview. Also, the Camera is deprecated. Thanks. – Sinan Dizdarević Dec 21 '18 at 11:33