0

I am trying to figure out the resolution of android phones in my app.
I was using

public float getBackCameraResolutionInMp() {

    try {
        int noOfCameras = Camera.getNumberOfCameras();
        float maxResolution = -1;
        long pixelCount = -1;
        Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
        Camera.getCameraInfo(BACK_CAMERA_ID, cameraInfo);
        if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
            try {
                releaseCameraAndPreview();
                if (camera == null) {
                    camera = Camera.open(BACK_CAMERA_ID);
                }
                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);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return maxResolution;
    } catch (Exception e) {
        logException(e, "CameraInfoFragment_getBackCameraResolutionInMp()");
        return -1;
    }

}

But it returns me approximate resolution not the exact. Like if the resolution is 16MP it returns me 15.55 MP. Can you please help me how to fugure out the exact resolution of camera?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Akaanksha
  • 161
  • 1
  • 14
  • Possible duplicate of [How to get real Camera max Megapixels of a device?](https://stackoverflow.com/questions/25590721/how-to-get-real-camera-max-megapixels-of-a-device) – Emanuel Sep 08 '17 at 07:34

1 Answers1

0

I think you should not divide by 1024000 but with 1000000. Here we are talking about Mega Pixels not Mega Bytes to use the the equality 1 Megabyte = 1,048,576 Bytes but 1 Megapixel = 1,000,000 Pixels. Plus 1024000 is wrong, it should have been 1048576 or 2^20. Dividing by a 1000000 will give you a number much more closer to 16MP.

pleft
  • 7,567
  • 2
  • 21
  • 45