5

My goal is to take the largest number of images from the camera without saving them, but I have no idea how to do this' operation. I know how to catch a 'image from the camera taking a picture, but as I do to get a stream from the camera without taking pictures?

I will not send photos via internet, but process them on the device. I have to take a video or a photo sequence ?!

1 Answers1

9

You can process pictures from the camera with the onPreviewFrame(byte[] data, Camera camera) Callback. Take a look at the docs: Link

private Camera.PreviewCallback previewCallback = new Camera.PreviewCallback() {
        @Override
        public void onPreviewFrame(byte[] data, Camera camera) {

        // Do something with the frame
       }
};

Update regarding your comment:

Try to get the bitmap the following way:

    Camera.Parameters parameters = camera.getParameters();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    YuvImage yuvImage = new YuvImage(data, parameters.getPreviewFormat(), parameters.getPreviewSize().width, parameters.getPreviewSize().height, null);
    yuvImage.compressToJpeg(new Rect(0, 0, parameters.getPreviewSize().width, parameters.getPreviewSize().height), 90, out);
    byte[] imageBytes = out.toByteArray();
    Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.length);


     out.flush();
     out.close();
IIIIIIIIIIIIIIIIIIIIII
  • 3,958
  • 5
  • 45
  • 70
  • Hi tanks you for Answered! I have a another problem after the implementation of your (apparently for the moment) solution, i have do "BitmapFactory.decodeByteArray(data, 0 , data.length);" but it give me the error "SkImageDecoder::Factory returned null"... any solution? The correct answer will score as after the 'I will have verified. – Paolo Mastrangelo Nov 30 '16 at 10:04
  • Compliments! It works perfectly, only observation is to capture the IOException on flush. I also found another solution for the conversion: http://stackoverflow.com/questions/1893072/getting-frames-from-video-image-in-android. Really thx man! – Paolo Mastrangelo Nov 30 '16 at 10:28
  • 1
    @PaoloMastrangelo Glad to help. I removed the try catch block so the code is more readable ;) – IIIIIIIIIIIIIIIIIIIIII Nov 30 '16 at 10:40