casper
casper

Reputation: 1411

Android Camera: Save preview frames to buffer?

I would like to use onPreviewFrame to save a predefined number of frames into buffer and later save them as png's.

There are many examples on how to do the whole capturing and saving in one go, but I need to do just the buffering of, let's say 3 consecutive frames first. Perhaps I could create an array of byte objects? I am new to java so any suggestions are welcome.

Upvotes: 0

Views: 2523

Answers (1)

yushulx
yushulx

Reputation: 12160

in case of out of memory, you have to limit your array size

    private ArrayList<byte[]> queue = new ArrayList<byte[]>(3);
    private Camera.PreviewCallback mPreviewCallback = new Camera.PreviewCallback() {

        @Override
        public void onPreviewFrame(byte[] data, Camera camera) {        
            // TODO Auto-generated method stub

            if (queue.size() == 3) {
                queue.remove(0);
            }
            queue.add(data);
        }

    };

Upvotes: 2

Related Questions