Java tutorial
//package com.java2s; //License from project: Open Source License import java.lang.reflect.Method; import android.hardware.Camera; public class Main { static Method addPreviewBufferMethod; /** Attempts to allocate and register the given number of preview callback buffers. Uses the camera's current preview * size to determine the size of the buffers. If the Android API doesn't support preview buffers, does nothing. * Returns true if successful. */ public static boolean createPreviewCallbackBuffers(Camera camera, int nbuffers) { if (addPreviewBufferMethod == null) return false; Camera.Size previewSize = camera.getParameters().getPreviewSize(); // 12 bits per pixel for preview buffer (8 chroma bytes, then average of 2 bytes each for Cr and Cb) 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; } } return true; } }