如何在Android设备中获取相机传感器尺寸?

前端之家收集整理的这篇文章主要介绍了如何在Android设备中获取相机传感器尺寸?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
谁能知道如何在 Android设备中获取相机的传感器尺寸?

谢谢

解决方法

从API级别21开始是可能的.从文档( 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

我用这种代码.请注意,可能不仅仅是一台摄像头:

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

请注意,需要捕获Exception CameraAccessException.

别忘了添加< uses-sdk android:minSdkVersion =“21”/>到你的清单.

原文链接:https://www.f2er.com/android/308695.html

猜你在找的Android相关文章