Android examples for Camera:Camera Preview
Attempts to allocate and register the given number of preview callback buffers.
//package com.java2s; import java.lang.reflect.Method; import android.hardware.Camera; public class Main { static Method addPreviewBufferMethod; public static boolean createPreviewCallbackBuffers(Camera camera, int nbuffers) { if (addPreviewBufferMethod == null) return false; Camera.Size previewSize = camera.getParameters().getPreviewSize(); int bufferSize = previewSize.width * previewSize.height * 3 / 2; for (int i = 0; i < nbuffers; i++) { byte[] buffer = new byte[bufferSize]; try { addPreviewBufferMethod.invoke(camera, buffer); } catch (Exception ignored) { return false; }//from w ww .ja v a 2s. com } return true; } }