I've used the ImageUtil
class provided in https://mcmap.net/q/502768/-android-camera2-api-yuv_420_888-to-jpeg within my git repo: https://github.com/ahasbini/cameraview/tree/camera_preview_imp (note the implementation is in camera_preview_imp
branch) to implement a frame preview callback. An ImageReader
is set to preview frames in the ImageFormat.YUV_420_888
format which will be converted into ImageFormat.JPEG
using the ImageUtil
class and send it to the frame callback. The demo app saves a frame from the callback to a file every 50 frames. All of the saved frame images are coming out distorted similar to below:
If I've changed the ImageReader
to use ImageFormat.JPEG
instead by doing the following changes in Camera2
:
mPreviewImageReader = ImageReader.newInstance(previewSize.getWidth(),
previewSize.getHeight(), ImageFormat.JPEG, /* maxImages */ 2);
mCamera.createCaptureSession(Arrays.asList(surface, mPreviewImageReader.getSurface()),
mSessionCallback, null);
the image is coming properly without any distortions however the frame rate drops significantly and the view starts to lag. Hence I believe the ImageUtil
class is not converting properly.
final image
with distortion is image written in a file? – BodycheckonImageAvailable(ImageReader reader)
(ImageReader.OnImageAvailableListener) method? – BodycheckCamera2
class within themOnPreviewAvailableListener
variable. – Ravel