简体   繁体   English

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

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

I am developing an Android application in 2.2, which uses Camera. 我正在开发2.2中的Android应用程序,它使用Camera。 Now Can anyone tell me that "Is it possible to programmatically determine the Camera Resolution in Megapixels in Android" 现在任何人都可以告诉我“是否有可能以编程方式确定Android中的百万像素的相机分辨率”

if you've got the camera object, try: 如果您有相机对象,请尝试:

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


int height = size.height;
int width = size.width;

What does image resolution mean? 图像分辨率意味着什么?

Resolution refers to the number of pixels in an image. 分辨率是指图像中的像素数。 Resolution is sometimes identified by the width and height of the image as well as the total number of pixels in the image. 有时通过图像的宽度和高度以及图像中的像素总数来确定分辨率。 For example, an image that is 2048 pixels wide and 1536 pixels high (2048X1536) contains (multiply) 3,145,728 pixels (or 3.1 Megapixels). 例如,宽2048像素,高1536像素(2048X1536)的图像包含(乘)3,145,728像素(或3.1百万像素)。 You could call it a 2048X1536 or a 3.1 Megapixel image. 您可以将其称为2048X1536或310万像素图像。 As the megapixels in the pickup device in your camera increase so does the possible maximum size image you can produce. 随着相机中拾音设备中的百万像素增加,您可以生成的最大尺寸图像也会增加。 This means that a 5 megapixel camera is capable of capturing a larger image than a 3 megapixel camera. 这意味着500万像素的摄像头能够拍摄比300万像素摄像头更大的图像。

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

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 在android清单中添加此权限

<uses-permission android:name="android.permission.CAMERA" />

Yes, that way works to me. 是的,这样对我有用。 One more note here, getPictureSize() will return a list of supported size with different heights and widths. 还有一点需要注意,getPictureSize()将返回一个支持大小的列表,其中包含不同的高度和宽度。 To calculate the resolution in pixel of device's camera, please get the biggest height & width from the size list. 要计算设备相机的像素分辨率,请从尺寸列表中获取最大高度和宽度。

You can you this to get the list of supported sizes. 您可以通过此方式获取支持的尺寸列表。 getSupportedSizes() getSupportedSizes()

The highest size would give you the camera resoultion in pixels. 最高尺寸会以像素为单位提供相机重新分配。

EDIT: Just in case you do not know. 编辑:以防你不知道。

Resolution in pixel = width X height 像素的分辨率=宽度X高度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM