0

In my case, I don't need to show the preview to the user and would like to capture the image from the service, to achieve this I have used ImageFormat .JPG to capture the images but output images are really very dark. I have tried this link in StackOverflow but it is not working.

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)

If I use the dummy surface texture view getting below error, after few seconds of app launch

E/BufferQueueProducer: [SurfaceTexture-1-20857-1] cancelBuffer: BufferQueue has been abandoned

Sandeep R
  • 2,284
  • 3
  • 25
  • 51

1 Answers1

0

First of all, you don't have to use a TextureView. The reason your preview is really dark is probably because of your CaptureRequest.builder. You want to control your Auto Exposure with for example, I explain later this below.

First, when you set your surface, you should set it as such:

builder.addTarget(mImageReader.getSurface());

Now on to the brightness issue, you can control your AE like this:

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

where getRange() is:

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);

If you want to know more about custom brightness etc. Check this out