就我而言,我不需要向用户显示预览,也不需要从服务中捕获图像,为此,我使用了 ImageFormat .JPG
捕获图像,但输出图像确实非常暗。我已经在StackOverflow中尝试过此link,但是它不起作用。
val streamConfigurationMap =
mCameraCharacteristics.get(CameraCharacteristics.SCALER_STREAM_CONFIGURATION_MAP) // Available stream configuration.
mPreviewSize = streamConfigurationMap!!.getOutputSizes(ImageFormat.JPEG)[0]
mCameraID = cameraId
mImageReader =
ImageReader.newInstance(mPreviewSize!!.width, mPreviewSize!!.height, ImageFormat.JPEG, 1)
mImageReader!!.setOnImageAvailableListener(onImageAvailable, mBackgroundHandler)
如果我使用虚拟表面纹理视图低于错误,则在应用启动几秒钟后
E / BufferQueueProducer:[SurfaceTexture-1-20857-1] cancelBuffer:BufferQueue已被放弃
答案 0 :(得分:0)
首先,您不必使用TextureView。您的预览真的很暗的原因可能是您的CaptureRequest.builder。例如,您想要控制自动曝光,下面我将对此进行解释。
首先,在设置表面时,应将其设置为:
builder.addTarget(mImageReader.getSurface());
现在要解决亮度问题,您可以像这样控制AE:
builder.set(CaptureRequest.CONTROL_AE_TARGET_FPS_RANGE,getRange());
其中getRange()是:
private Range<Integer> getRange() {
CameraCharacteristics chars = null;
try {
CameraManager manager = (CameraManager) ((Activity)getContext()).getSystemService(Context.CAMERA_SERVICE);
chars = manager.getCameraCharacteristics(mCameraId);
Range<Integer>[] ranges = chars.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES);
Range<Integer> result = null;
for (Range<Integer> 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;
} catch (CameraAccessException e) {
e.printStackTrace();
return null;
}
}
mImageReader = ImageReader.newInstance(hardcoded_width, hardcoded_height, ImageFormat.YUV_420_888, 2);
mImageReader.setOnImageAvailableListener(mVideoCapture, mBackgroundHandler);
如果您想进一步了解自定义亮度等。Check this out