Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[Roman Herasymenko] New Android Camera API

[Roman Herasymenko] New Android Camera API

Presentation from GDG DevFest - the biggest Google related event in Ukraine. October 24-25, Lviv. Learn more at http://devfest.gdg.org.ua/

Google Developers Group Lviv

October 25, 2014
Tweet

More Decks by Google Developers Group Lviv

Other Decks in Programming

Transcript

  1. #dfua Pre-L camera API - Limited access to streaming image

    data - Limited information about camera state - No manual camera control - Designed for ‘Point and shoot’
  2. #dfua Opening the camera CameraManager manager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); manager.openCamera("0",

    new StateListener(){ @Override public void onOpened(CameraDevice device){ mCameraDevice = device; ... } ... }, null);
  3. #dfua Creating surfaces CameraCharacteristics chars = (mCameraManager).getCameraCharacteristics("0"); StreamConfigurationMap configs =

    chars.get(CameraCharacteristics. SCALER_STREAM_CONFIGURATION_MAP); Size [] sizes = configs.getOutputSizes(ImageFormat.JPEG); ImageReader mImageReader = ImageReader.newInstance(sizes[0].getWidth(), sizes[0]. getHeight(), ImageFormat.JPEG, 2); Surface jpegCapture = mImageReader.getSurface();
  4. #dfua Creating a CaptureSession List<Surface> surfaces = new ArrayList<Surface>(); surfaces.add(previewSurface);

    surfaces.add(jpegCaptureSurface); mCameraDevice.createCaptureSession(surfaces, new CameraCaptureSession. StateCallback() { @Override public void onConfigured(CameraCaptureSession session) { .. } }, null);
  5. #dfua Building requests previewRequestBuilder = mCameraDevice.createCaptureRequest(CameraDevice. TEMPLATE_PREVIEW); previewRequestBuilder.addTarget(previewSurface); captureRequestBuilder =

    mCameraDevice.createCaptureRequest(CameraDevice. TEMPLATE_STILL_CAPTURE); captureRequestBuilder.addTarget(jpegCaptureSurface); captureRequest = captureRequestBuilder.build(); previewRequest = previewRequestBuilder.build();
  6. #dfua Setting up a Builder Builder builder = mCameraDevice.createCaptureRequest(CameraDevice. TEMPLATE_STILL_CAPTURE);

    builder.addTarget(jpegCaptureSurface); builder.set(CaptureRequest.CONTROL_AWB_MODE, CaptureRequest. CONTROL_AWB_MODE_INCANDESCENT); builder.set(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata. CONTROL_EFFECT_MODE_SEPIA); builder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_SINGLE);
  7. #dfua Submitting request mCameraCaptureSession.capture(request, new CaptureListener() { @Override public void

    onCaptureStarted(CameraCaptureSession session, CaptureRequest request, long timestamp) { ... } @Override public void onCaptureCompleted(CameraCaptureSession session, CaptureRequest request, TotalCaptureResult result) { ... } }, null);