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

发布于 2024-11-27 19:39:58 字数 88 浏览 2 评论 0原文

我正在2.2中开发一个Android应用程序,它使用Camera。 现在谁能告诉我“是否有可能以编程方式确定 Android 中的相机分辨率(以百万像素为单位)”

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 Megapixels in Android"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

樱&纷飞 2024-12-04 19:39:58

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

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


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

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;
再见回来 2024-12-04 19:39:58

图像分辨率是什么意思?

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

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

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). You could call it a 2048X1536 or a 3.1 Megapixel image. 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.

Example: 1936 x 1552 / 1024000 = 3 Mega Pixels

明媚如初 2024-12-04 19:39:58

尝试

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;
}

在 android 清单中添加此权限

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

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

<uses-permission android:name="android.permission.CAMERA" />
绝情姑娘 2024-12-04 19:39:58

您可以通过此方法获取支持的尺寸列表。
getSupportedSizes()

最大尺寸将为您提供相机分辨率(以像素为单位)。

编辑:
以防万一你不知道。

分辨率(像素)= 宽度 X 高度

You can you this to get the list of supported sizes.
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

天邊彩虹 2024-12-04 19:39:58

是的,这种方式对我有用。
这里还要注意一点, getPictureSize() 将返回具有不同高度和宽度的受支持尺寸的列表。要计算设备相机的像素分辨率,请获取最大高度和最大高度。尺寸列表中的宽度。

Yes, that way works to me.
One more note here, getPictureSize() will return a list of supported size with different heights and widths. To calculate the resolution in pixel of device's camera, please get the biggest height & width from the size list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文