4

The function onImageAvailable handles the image save, how can it be used to set a preview for the user to review, typically on an ImageView.

        @Override
        public void onImageAvailable(ImageReader reader) {
            //mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), mFile));
            Image image = reader.acquireNextImage();
            ByteBuffer buffer = image.getPlanes()[0].getBuffer();
            byte[] bytes = new byte[buffer.remaining()];
            buffer.get(bytes);
            Bitmap bmp = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
            setPreviewImage(bmp);
        }

This does not work for me.

patrickfdsouza
  • 747
  • 6
  • 17
  • Please explain what "this does not work for me" means. – CommonsWare Aug 23 '15 at 14:39
  • If you just want a preview on the screen, it is highly suggested to have your CameraCaptureSession send the image data directly to a SurfaceView or SurfaceTexture, rather than turning it into a bitmap image and sending it to an ImageView. Is there a reason you want to do it this way? – rcsumner Aug 23 '15 at 19:15
  • @CommonsWare Do you suggest doing something inside the onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) of the CameraCaptureSession.CaptureCallback? Where do I get the image data from? – patrickfdsouza Aug 24 '15 at 06:25
  • I suggest that you explain what "this does not work for me" means. – CommonsWare Aug 24 '15 at 12:29
  • When I try to set the preview image bitmap to the ImageView; setPreviewImage(bmp), it does not show any image at all. – patrickfdsouza Aug 25 '15 at 08:09
  • +rcsumner do you have an example of how do send image data directly ro SurfaceTexture? – Daniel Viglione Jul 07 '17 at 01:37

0 Answers0