Пример #1
0
 public void shutdown() {
   if (camera != null) {
     camera.stopPreview();
     camera.release();
     detectThread.stop();
     camera = null;
   }
   user.onEyeStopped();
 }
Пример #2
0
  @Override
  public void surfaceCreated(SurfaceHolder arg0) {
    camera = Camera.open();
    Camera.Parameters params = camera.getParameters();
    camera.setDisplayOrientation(90);
    params.setRotation(90);
    params.set("orientation", "landscape");
    params.set("rotation", 90);
    params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
    Camera.Size previewSize = params.getPreviewSize();
    List<Camera.Size> previewSizes = params.getSupportedPreviewSizes();
    int i = 0;
    for (Camera.Size cs : previewSizes) {
      Log.d(MarvinActivity.TAG, "Camera - supports:(" + (i++) + ") " + cs.width + "x" + cs.height);
    }

    previewSize.width = 720;
    previewSize.height = 480;

    params.setSceneMode("portrait");
    Log.d(MarvinActivity.TAG, "w: " + previewSize.width + " h: " + previewSize.height);
    List<Integer> formats = params.getSupportedPreviewFormats();
    for (Integer format : formats) {
      Log.d(MarvinActivity.TAG, "Camera - supports preview format: " + format);
    }
    params.setPreviewSize(previewSize.width, previewSize.height);
    camera.setParameters(params);

    detectThread = new FaceDetectThread(context, user, params);
    detectThread.start();
    camera.setPreviewCallback(detectThread);
    try {
      camera.setPreviewDisplay(cameraView.getHolder());
      camera.startPreview();
      Log.d(MarvinActivity.TAG, "preview started");
    } catch (Exception e) {
      Log.e(MarvinActivity.TAG, e.getMessage(), e);
    }
    user.onEyeStarted();
  }