can anyone know how to get sensor size of camera in android device ?
Thanks
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With