Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get a stream of bitmap from camera?

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 ?!

like image 318
Paolo Mastrangelo Avatar asked Nov 30 '16 08:11

Paolo Mastrangelo


1 Answers

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();
like image 150
IIIIIIIIIIIIIIIIIIIIII Avatar answered Nov 03 '22 10:11

IIIIIIIIIIIIIIIIIIIIII