Determining Camera Resolution (i.e. Megapixels) Programmatically in Android Determining Camera Resolution (i.e. Megapixels) Programmatically in Android android android

Determining Camera Resolution (i.e. Megapixels) Programmatically in Android


if you've got the camera object, try:

android.hardware.Camera.Parameters parameters = camera.getParameters();android.hardware.Camera.Size size = parameters.getPictureSize();int height = size.height;int width = size.width;


What does image resolution mean?

Resolution refers to the number of pixels in an image. Resolution is sometimes identified by the width and height of the image as well as the total number of pixels in the image. For example, an image that is 2048 pixels wide and 1536 pixels high (2048X1536) contains (multiply) 3,145,728 pixels (or 3.1 Megapixels). You could call it a 2048X1536 or a 3.1 Megapixel image. As the megapixels in the pickup device in your camera increase so does the possible maximum size image you can produce. This means that a 5 megapixel camera is capable of capturing a larger image than a 3 megapixel camera.

Example: 1936 x 1552 / 1024000 = 3 Mega Pixels


Try this

public float getBackCameraResolutionInMp(){    int noOfCameras = Camera.getNumberOfCameras();    float maxResolution = -1;    long pixelCount = -1;    for (int i = 0;i < noOfCameras;i++)    {        Camera.CameraInfo cameraInfo = new CameraInfo();        Camera.getCameraInfo(i, cameraInfo);        if (cameraInfo.facing == CameraInfo.CAMERA_FACING_BACK)        {            Camera camera = Camera.open(i);;            Camera.Parameters cameraParams = camera.getParameters();            for (int j = 0;j < cameraParams.getSupportedPictureSizes().size();j++)            {                long pixelCountTemp = cameraParams.getSupportedPictureSizes().get(j).width * cameraParams.getSupportedPictureSizes().get(j).height; // Just changed i to j in this loop                if (pixelCountTemp > pixelCount)                {                    pixelCount = pixelCountTemp;                    maxResolution = ((float)pixelCountTemp) / (1024000.0f);                }            }            camera.release();        }    }    return maxResolution;}

Add this permission in android manifest

<uses-permission android:name="android.permission.CAMERA" />