我想设置相机的曝光。当相机启动时,我想设置较高的值,当它停止时,它被设置为较低的值。所以我使用了下面的代码。在模拟器上,它显示的范围是-9到9,但当我连接物理usb相机时,它的低范围和高范围显示为0值。我正试图获得 曝光时间范围,它也显示为空。Range exposure_time= cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_EXPOSURE_TIME_RANGE)。
public void setExposure(Context context, double exposureAdjustment) {
CameraManager manager = (CameraManager) context.getSystemService(Context.CAMERA_SERVICE);
try {
camId = manager.getCameraIdList()[0];
} catch (CameraAccessException e) {
e.printStackTrace();
try {
cameraCharacteristics = manager.getCameraCharacteristics(camId);
} catch (CameraAccessException e) {
e.printStackTrace();
Range<Integer> range1 = cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE);
Log.d(TAG,"range1" +range1);
Integer minExposure = range1.getLower();
Log.d(TAG,"minExposure" +minExposure);
Integer maxExposure = range1.getUpper();
Log.d(TAG,"maxExposure" +maxExposure);
if (minExposure != 0 || maxExposure != 0) {
float newCalculatedValue = 0;
if (exposureAdjustment >= 0) {
newCalculatedValue = (float) (maxExposure * exposureAdjustment);
} else {
newCalculatedValue = (float) (minExposure * exposureAdjustment);
if (requestBuilder != null) {
CaptureRequest captureRequest = requestBuilder.build();
try {
captureSession.setRepeatingRequest(captureRequest, captureCallback, null);
} catch (CameraAccessException e) {
e.printStackTrace();
requestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, (int) newCalculatedValue);
Log.d(TAG,"New Calculated VAlue "+newCalculatedValue);
try {
captureSession.capture(captureRequest,captureCallback,null);
} catch (CameraAccessException e) {
e.printStackTrace();