set Camera Preview Callback With Buffer - Android android.hardware

Android examples for android.hardware:Back Camera

Description

set Camera Preview Callback With Buffer

Demo Code

import android.graphics.Bitmap;
import android.hardware.Camera;
import java.lang.reflect.Method;
import java.util.Collections;
import java.util.List;

public class Main{

    static Method setPreviewCallbackWithBufferMethod;
    /** Sets the given callback object on the given camera. Calls setPreviewCallbackWithBuffer if the Android API supports it,
     * otherwise calls setPreviewCallback.
     *//* www  .j  ava2 s.c  om*/
    public static boolean setPreviewCallbackWithBuffer(Camera camera,
            Camera.PreviewCallback callback) {
        if (setPreviewCallbackWithBufferMethod == null) {
            camera.setPreviewCallback(callback);
            return false;
        }
        try {
            setPreviewCallbackWithBufferMethod.invoke(camera, callback);
            return true;
        } catch (Exception ignored) {
            camera.setPreviewCallback(callback);
            return false;
        }
    }

}

Related Tutorials