在Android中以编程方式确定摄像机分辨率(即百万像素)

YuD*_*oid 23 camera android resolution

我正在开发2.2中的Android应用程序,它使用Camera.现在任何人都可以告诉我"是否有可能以编程方式确定Android中的百万像素的相机分辨率"

小智 17

如果您有相机对象,请尝试:

android.hardware.Camera.Parameters parameters = camera.getParameters();
android.hardware.Camera.Size size = parameters.getPictureSize();


int height = size.height;
int width = size.width;
Run Code Online (Sandbox Code Playgroud)

  • YuDroid,使用@wAroXxX提供的答案,它给你相机将输出的图片的高度和宽度,然后使用PravinCG给出的公式"像素中的分辨率=宽度X高度"这给出了像素和分辨率的分辨率那是1,024,000.这将为您提供MegaPixels的分辨率.所以:Megapixels =(width*Height)/ 1024000; (4认同)

Hea*_*Vay 10

图像分辨率意味着什么?

分辨率是指图像中的像素数.有时通过图像的宽度和高度以及图像中的像素总数来确定分辨率.例如,宽2048像素,高1536像素(2048X1536)的图像包含(乘)3,145,728像素(或3.1百万像素).您可以将其称为2048X1536或310万像素图像.随着相机中拾音设备中的百万像素增加,您可以生成的最大尺寸图像也会增加.这意味着500万像素的摄像头能够拍摄比300万像素摄像头更大的图像.

示例:1936 x 1552/1024000 = 3百万像素


Sat*_*ish 5

试试这个

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;
}
Run Code Online (Sandbox Code Playgroud)

在android清单中添加此权限

<uses-permission android:name="android.permission.CAMERA" />
Run Code Online (Sandbox Code Playgroud)