Android 相机方向传感,如何在Android设备中获取相机传感器尺寸?[通俗易懂]

2022-08-22 10:26:23 浏览数 (1)

大家好,又见面了,我是你们的朋友全栈君。

从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://javaforall.cn/136817.html原文链接:https://javaforall.cn

0 人点赞