Ejemplo n.º 1
0
  @Override
  public void onPreviewFrame(byte[] data, Camera camera) {

    if (listener != null) listener.cameraPreviewFrame(data);

    cameraWrapper.frameReceived(data);

    if (fpsCounter.frame()) {
      Log.i(TAG, "Camera capture FPS: " + fpsCounter.getFPS());
    }
  }
Ejemplo n.º 2
0
  @Override
  public void surfaceDestroyed(SurfaceHolder holder) {
    // Surface will be destroyed when we return, so stop the preview.
    // Because the CameraDevice object is not a shared resource, it's very
    // important to release it when the activity is paused.

    if (camera != null) {

      camera.setPreviewCallback(null);
      camera.stopPreview();

      camera.release();
      camera = null;
    }

    if (listener != null) listener.cameraPreviewStopped();
  }
Ejemplo n.º 3
0
  @SuppressWarnings("deprecation") // setPreviewFrameRate, getPreviewFrameRate
  @Override
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {

    if (camera == null) {
      // Camera wasn't opened successfully?
      Log.e(TAG, "No camera in surfaceChanged");
      return;
    }

    Log.i(TAG, "Surfaced changed, setting up camera and starting preview");

    String camResolution =
        PreferenceManager.getDefaultSharedPreferences(getContext())
            .getString(
                "pref_cameraResolution",
                getResources().getString(R.string.pref_defaultValue_cameraResolution));
    String[] dims = camResolution.split("x", 2);
    Camera.Parameters parameters = camera.getParameters();
    parameters.setPreviewSize(Integer.parseInt(dims[0]), Integer.parseInt(dims[1]));
    parameters.setPreviewFrameRate(30);
    camera.setParameters(parameters);

    parameters = camera.getParameters();
    captureWidth = parameters.getPreviewSize().width;
    captureHeight = parameters.getPreviewSize().height;
    captureRate = parameters.getPreviewFrameRate();
    int pixelformat = parameters.getPreviewFormat(); // android.graphics.imageformat
    PixelFormat pixelinfo = new PixelFormat();
    PixelFormat.getPixelFormatInfo(pixelformat, pixelinfo);
    int cameraIndex = 0;
    boolean cameraIsFrontFacing = false;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
      Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
      cameraIndex =
          Integer.parseInt(
              PreferenceManager.getDefaultSharedPreferences(getContext())
                  .getString("pref_cameraIndex", "0"));
      Camera.getCameraInfo(cameraIndex, cameraInfo);
      if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) cameraIsFrontFacing = true;
    }

    mParent.onCameraConfigured(captureWidth, captureHeight, w, h);

    int bufSize =
        captureWidth
            * captureHeight
            * pixelinfo.bitsPerPixel
            / 8; // For the default NV21 format, bitsPerPixel = 12.
    Log.i(
        TAG,
        "Camera buffers will be "
            + captureWidth
            + "x"
            + captureHeight
            + "@"
            + pixelinfo.bitsPerPixel
            + "bpp, "
            + bufSize
            + "bytes.");
    cameraWrapper = new CameraWrapper(camera);
    cameraWrapper.configureCallback(
        this, true, 10, bufSize); // For the default NV21 format, bitsPerPixel = 12.

    camera.startPreview();

    if (listener != null)
      listener.cameraPreviewStarted(
          captureWidth, captureHeight, captureRate, cameraIndex, cameraIsFrontFacing);
  }