Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Camera Sensor Size in android device?

can anyone know how to get sensor size of camera in android device ?

Thanks

like image 240
SBJ Avatar asked Nov 12 '11 11:11

SBJ


1 Answers

It is possible as of API level 21. From the documentation (https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#SENSOR_INFO_PHYSICAL_SIZE):

public static final Key SENSOR_INFO_PHYSICAL_SIZE

The physical dimensions of the full pixel array. [...]

Units: Millimeters

I use this kind of code. Beware, there might be more than just one camera:

import android.hardware.camera2.CameraAccessException;
import android.hardware.camera2.CameraCharacteristics;
import android.hardware.camera2.CameraManager;

private SizeF getCameraResolution(int camNum)
{
    SizeF size = new SizeF(0,0);
    CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE);
    try {
        String[] cameraIds = manager.getCameraIdList();
        if (cameraIds.length > camNum) {
            CameraCharacteristics character = manager.getCameraCharacteristics(cameraIds[camNum]);
            size = character.get(CameraCharacteristics.SENSOR_INFO_PHYSICAL_SIZE);
        }
    }
    catch (CameraAccessException e)
    {
        Log.e("YourLogString", e.getMessage(), e);
    }
    return size;
}

Note that Exception CameraAccessException needs to be caught.

Don't forget to add <uses-sdk android:minSdkVersion="21" /> to your manifest.

like image 137
DomTomCat Avatar answered Sep 16 '22 16:09

DomTomCat