Camera2basic应用程序,在Android 6.0 LGG3中有非常黑暗的预览

新的API,也许只在LG G3上,似乎有些变化。

我正在使用示例代码 。

在我的nexus 4上,代码运行完美,但在LGG3上更新到Android 6.0却没有。 有任何想法吗?

我玩了设置,但没有运气,这仍然适用于Nexus 4:

mPreviewRequestBuilder.set(CaptureRequest.BLACK_LEVEL_LOCK, false); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AWB_LOCK, false); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_AUTO); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_ANTIBANDING_MODE, CaptureRequest.CONTROL_AE_ANTIBANDING_MODE_AUTO); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_EXPOSURE_COMPENSATION, 0); //mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, Range.create(1000,1000)); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, 0); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO); mPreviewRequestBuilder.set(CaptureRequest.COLOR_CORRECTION_MODE, CaptureRequest.CONTROL_MODE_AUTO); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_CAPTURE_INTENT, CaptureRequest.CONTROL_CAPTURE_INTENT_PREVIEW); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); 

Camera2 API的FPS范围似乎使用了旧版Camera API的另一个尺度。 因此,如果您正在接收支持的预览fps范围(0,30000),则应将值设置为1000:

 mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, Range.create(0, 30)); 

尝试这是否有帮助,因为它有助于旧的Camera API。

我find了适合我的解决方案。 解决方案是设置设备支持的FPS范围。

 mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE, getRange()); 

获取范围的function:

 private Range getRange() { CameraCharacteristics chars = mCameraManager.getCameraCharacteristics(mCameraId); Range[] ranges = chars.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES); Range result = null; for (Range range : ranges) { int upper = range.getUpper(); // 10 - min range upper for my needs if (upper >= 10) { if (result == null || upper < result.getUpper().intValue()) { result = range; } } } if (result == null) { result = ranges[0]; } return result; } 

更新:其他设置(如果有人感兴趣)

 mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_LOCK, false); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE, CameraMetadata.CONTROL_AE_MODE_ON); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CameraMetadata.CONTROL_AWB_MODE_AUTO); mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE); mPreviewRequestBuilder.set(CaptureRequest.STATISTICS_FACE_DETECT_MODE, CameraMetadata.STATISTICS_FACE_DETECT_MODE_SIMPLE); 

设置正确的CONTROL_AE_TARGET_FPS_RANGE是关键。

这可能会出错的原因很少。 正如@Anton Malyshev所说,某些设备会为您提供CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES乘以1000.因此,在设置CONTROL_AE_TARGET_FPS_RANGE时,您必须将其除以1000。

我想出的另一个原因是,根据分辨率,自动曝光会因更高的FPS而失败。 所以我做的一个简单的解决方法是将较低的范围设置为0。

例如,如果CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES具有24000:24000,则在将较低值分割并设置为0之后,范围将为0:24