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

后端 未结 5 468
感情败类
感情败类 2020-12-09 03:44

I am developing an Android application in 2.2, which uses Camera. Now Can anyone tell me that \"Is it possible to programmatically determine the Camera Resolution in Megapix

5条回答
  •  被撕碎了的回忆
    2020-12-09 04:13

    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

    
    

提交回复
热议问题