0
我想弄清楚我的應用程序中的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。你能幫我解決相機的確切分辨率嗎?
可能重複的[如何獲得真正的相機最大百萬像素的設備?](https://stackoverflow.com/questions/25590721/how-to-get-real-camera-max-megapixels-of-a-設備) –