如何获得相机传感器尺寸在Android设备? [英] How to get Camera Sensor Size in android device?

查看:732
本文介绍了如何获得相机传感器尺寸在Android设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以知道如何得到相机的传感器尺寸在Android设备?

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

感谢

推荐答案

这是可能的,API级别21.从文件(<一href=\"https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#SENSOR_INFO_PHYSICAL_SIZE\" rel=\"nofollow\">https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#SENSOR_INFO_PHYSICAL_SIZE):

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):

公共静态最后一个关键SENSOR_INFO_PHYSICAL_SIZE

public static final Key SENSOR_INFO_PHYSICAL_SIZE

全像素阵列的物理尺寸。 [...]

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

单位:毫米

我用这种code的。当心,有可能比只有一个摄像头更多:

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

注意异常 CameraAccessException 需要被抓住。

不要忘了添加&LT;采用-SDK安卓的minSdkVersion =21/&GT; 您清单

这篇关于如何获得相机传感器尺寸在Android设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆