我正在尝试使用camera2 API从服务拍照。我的照片太暗了。我尝试设置CONTROL_AE_EXPOSURE_COMPENSATION
并使用了不同的相机模板,但这无济于事。谁能帮我为什么我得到暗图片?这是我的代码:
private final ImageReader.OnImageAvailableListener onImageAvailableListener = (ImageReader imReader)-> {
//get image and processes
};
private void takePicture() throws CameraAccessException {
if (null == cameraDevice) {
return;
}
final CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraDevice.getId());
Size[] jpegSizes = null;
StreamConfigurationMap streamConfigurationMap = characteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP);//setting streamConfigurationMap
if (streamConfigurationMap != null) {
jpegSizes = streamConfigurationMap.getOutputSizes(ImageFormat.JPEG);
}
final boolean jpegSizesNotEmpty = jpegSizes != null && 0 < jpegSizes.length;
int width = jpegSizesNotEmpty ? jpegSizes[0].getWidth() : 640;
int height = jpegSizesNotEmpty ? jpegSizes[0].getHeight() : 480;
final ImageReader reader = ImageReader.newInstance(width, height, ImageFormat.JPEG, 1);
final List<Surface> outputSurfaces = new ArrayList<>();
outputSurfaces.add(reader.getSurface());
final CaptureRequest.Builder captureBuilder = cameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);//setting template
captureBuilder.addTarget(reader.getSurface());
captureBuilder.set(CaptureRequest.CONTROL_MODE, CameraMetadata.CONTROL_MODE_AUTO);//setting CONTROL_MODE
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getOrientation());//setting mobile orientation
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);//setting ae mode
captureBuilder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest.CONTROL_AWB_MODE_AUTO);//setting white balance
captureBuilder.set(CaptureRequest.COLOR_CORRECTION_ABERRATION_MODE, CameraMetadata.COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY);//setting color correction
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);//setting auto focus
captureBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START);//setting auto focus
reader.setOnImageAvailableListener(onImageAvailableListener, null);
cameraDevice.createCaptureSession(outputSurfaces, new CameraCaptureSession.StateCallback() {
@Override
public void onConfigured(@NonNull CameraCaptureSession session) {
cameraCaptureSession = session;
try {//taking picture
HandlerThread handlerThread = new HandlerThread("MyHandlerThread");
handlerThread.start();
Looper looper = handlerThread.getLooper();
Handler handler = new Handler(looper);
cameraCaptureSession.capture(captureBuilder.build(), captureListener,handler);
} catch (final CameraAccessException e) {
Log.e("error capture" , e.getMessage());
}
}
@Override
public void onConfigureFailed(@NonNull CameraCaptureSession session) {//
}
}
, null);
}
编辑:我的应用程序没有任何UI,整个程序仅在后台运行。我已经与其他(三星)手机进行了测试,但是使用相同的android版本(6.0.1)的图像在小米手机中太暗了。我尝试添加延迟,并尝试TEMPLATE_PREVIEW
并留下了50张第一张图片对我没有任何帮助。