Paolo Mastrangelo Paolo Mastrangelo - 3 months ago 35
Android Question

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


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