예제 #1
0
    @Override
    public void onImageAvailable(ImageReader imageReader) {
      Image image = imageReader.acquireNextImage();
      ByteBuffer buffer = image.getPlanes()[0].getBuffer();
      byte[] bytes = new byte[buffer.remaining()];

      buffer.get(bytes);
      image.close();

      bus.post(new PictureTakenEvent(xact.process(new ImageContext(ctxt, bytes))));
    }
예제 #2
0
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
      camera.setParameters(previewParams);

      if (data != null) {
        new ImageCleanupTask(getContext(), data, cameraId, xact).start();
      }

      if (!xact.useSingleShotMode()) {
        startPreview();
      }
    }
예제 #3
0
  public void takePicture(final PictureTransaction xact) {
    if (inPreview) {
      if (isAutoFocusing) {
        throw new IllegalStateException("Camera cannot take a picture while auto-focusing");
      } else {
        previewParams = camera.getParameters();

        Camera.Parameters pictureParams = camera.getParameters();
        Camera.Size pictureSize = xact.host.getPictureSize(xact, pictureParams);

        pictureParams.setPictureSize(pictureSize.width, pictureSize.height);
        pictureParams.setPictureFormat(ImageFormat.JPEG);

        if (xact.flashMode != null) {
          pictureParams.setFlashMode(xact.flashMode);
        }

        if (!onOrientationChange.isEnabled()) {
          setCameraPictureOrientation(pictureParams);
        }

        camera.setParameters(xact.host.adjustPictureParameters(xact, pictureParams));
        xact.cameraView = this;

        postDelayed(
            new Runnable() {
              @Override
              public void run() {
                try {
                  camera.takePicture(xact, null, new PictureTransactionCallback(xact));
                } catch (Exception e) {
                  android.util.Log.e(getClass().getSimpleName(), "Exception taking a picture", e);
                  // TODO get this out to library clients
                }
              }
            },
            xact.host.getDeviceProfile().getPictureDelay());

        inPreview = false;
      }
    } else {
      throw new IllegalStateException(
          "Preview mode must have started before you can take a picture");
    }
  }
예제 #4
0
  public void takePicture(boolean needBitmap, boolean needByteArray) {
    PictureTransaction xact = new PictureTransaction(getHost());

    takePicture(xact.needBitmap(needBitmap).needByteArray(needByteArray));
  }