我想在我的应用程序中弄清楚Android手机的分辨率 我正在使用
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;
}
}
但是它给我的大致分辨率并不准确。就像分辨率是16MP一样,它返回15.55 MP。你能帮我解决一下如何确定相机的精确分辨率吗?
答案 0 :(得分:0)
我认为你不应该用1024000
除以1000000
。在这里,我们讨论Mega Pixels
而非Mega Bytes
使用等同1 Megabyte = 1,048,576 Bytes
但1 Megapixel = 1,000,000 Pixels
。加1024000
错误,应该是1048576
或2^20
。除以1000000
将使您的数字更接近16MP。