Urban
Urban

Reputation: 585

Set the camera resolution with google vision android

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.

Upvotes: 0

Views: 2091

Answers (1)

Elvis Xia - MSFT
Elvis Xia - MSFT

Reputation: 10841

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;
    }
}

Upvotes: 3

Related Questions