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?