开发者

Determining Camera Resolution (i.e. Megapixels) Programmatically in 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 th开发者_Go百科e Camera Resolution in Megapixels in 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). 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


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" />


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜