v0.13.4
v1.0.0-beta3.11v1.0.0-beta3.10v1.0.0-beta3.9v0.13.4v0.13.2

CameraKit Documentation - v0.13.4

  1. Setup
  2. Usage
  3. Capturing Images
  4. CameraView Attributes
  5. Permissions
  6. Sizing
  7. Events

Setup

Add CameraKit to the dependencies block in your app level build.gradle:

compile 'com.wonderkiln:camerakit:0.13.4'

Usage

To use CameraKit, add a CameraView to your layout:

<com.wonderkiln.camerakit.CameraView
    android:id="@+id/camera"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:adjustViewBounds="true" />

Override onResume and onPause in your activity, and make calls respectively to CameraView.start() and CameraView.stop().

@Override
protected void onResume() {
    super.onResume();
    cameraView.start();
}

@Override
protected void onPause() {
    cameraView.stop();
    super.onPause();
}

Capturing Images

To capture an image call CameraView.captureImage(). Then setup a CameraListener to handle the image callback.

Example

camera.setCameraListener(new CameraListener() {
    @Override
    public void onPictureTaken(byte[] picture) {
        super.onPictureTaken(picture);

        // Create a bitmap    
        Bitmap result = BitmapFactory.decodeByteArray(picture, 0, picture.length);
    }
 });

camera.captureImage();

Capturing Video

To capture video call CameraView.startRecordingVideo() to start, and CameraView.stopRecordingVideo() to finish. Setup a CameraListener to handle the video callback.

Example

camera.setCameraListener(new CameraListener() {
    @Override
    public void onVideoTaken(File video) {
        super.onVideoTaken(video);
        // The File parameter is an MP4 file.
    }
});

camera.startRecordingVideo();
camera.postDelayed(new Runnable() {
    @Override
    public void run() {
        camera.stopRecordingVideo();
    }
}, 2500);

Additional Video Methods

Function Description Example
stopVideo Stop recording video cameraView.stopVideo()
getPreviewSize Get size of camera preview Size cameraView.getPreviewSize();
getCaptureSize Get size of capture cameraView.getCaptureSize();

CameraView Attributes

<com.flurgle.camerakit.CameraView xmlns:camerakit="http://schemas.android.com/apk/res-auto"
    android:id="@+id/camera"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    camerakit:ckFacing="back"
    camerakit:ckFlash="off"
    camerakit:ckFocus="continuous"
    camerakit:ckMethod="standard"
    camerakit:ckZoom="pinch"
    camerakit:ckPermissions="strict"
    camerakit:ckCropOutput="true"  
    camerakit:ckJpegQuality="100"
    camerakit:ckVideoQuality="480p"
    android:adjustViewBounds="true" />
Attribute Values Default Value
ckFacing back, front back
ckFlash off, on, auto off
ckFocus off, continuous, tap continuous
ckMethod standard, still, speed standard
ckZoom off, pinch off
ckPermissions strict, lazy, picture strict
ckCropOutput true, false false
ckJpegQuality 0 <= n <= 100 100
ckVideoQuality max480p, max720p, max1080p,
max2160p, highest, lowest, qvga
max480p
ckVideoBitRate 0 <= n <= MAX_INT unset

ckFacing

Format Method
XML app:ckFacing="back"
Java cameraView.setFacing(CameraKit.Constants.FACING_BACK);

Possible values:

  • back, FACING_BACK
  • front, FACING_FRONT

Other Methods

int cameraView.getFacing()
boolean cameraView.isFacingFront()
boolean cameraView.isFacingBack()

ckFlash

Values: off, on, auto, torch

Format Method
XML app:ckFlash="off"
Java cameraView.setFlash(CameraKit.Constants.FLASH_OFF);

Possible values:

  • off, FLASH_OFF
  • on, FLASH_ON
  • auto, FLASH_AUTO
  • torch, FLASH_TORCH

Other Methods

int getFlash()

ckFocus

Format Method
XML app:ckFocus="continuous"
Java cameraView.setFocus(CameraKit.Constants.FOCUS_CONTINUOUS);

Possible values:

  • off, FOCUS_OFF
  • continuous, FOCUS_CONTINUOUS
  • tap, FOCUS_TAP

ckMethod

Format Method
XML app:ckMethod="standard"
Java cameraView.setMethod(CameraKit.Constants.METHOD_STANDARD);

Possible values:

  • standard, METHOD_STANDARD
  • still, METHOD_STILL
  • speed, METHOD_SPEED

Additional Notes:

When you use METHOD_STANDARD (camerakit:ckMethod="standard"), images will be captured using the normal camera API capture method using the shutter.

When you use METHOD_STILL (camerakit:ckMethod="still"), images will be captured by grabbing a single frame from the preview. This behavior is the same as SnapChat and Instagram. This method has a higher rate of motion blur but can be a better experience for users with slower cameras.


ckZoom

Format Method
XML app:ckZoom="off"
Java cameraView.setZoom(CameraKit.Constants.ZOOM_OFF);

Possible values:

  • off, ZOOM_OFF
  • pinch, ZOOM_PINCH

ckPermissions

Format Method
XML app:ckPermissions="strict"
Java cameraView.setPermissions(CameraKit.Constants.PERMISSIONS_STRICT);

Possible values:

  • strict, PERMISSIONS_STRICT
  • lazy, PERMISSIONS_LAZY
  • picture, PERMISSIONS_PICTURE

ckCropOutput

Format Method
XML app:ckCropOutput="false"
Java cameraView.setCropOutput(false);

Possible values:

  • true
  • false

ckJpegQuality

Format Method
XML app:ckJpegQuality="100"
Java cameraView.setJpegQuality(100);

Possible values:

  • int: [0, 100]
cameraView.setJpegQuality(100);

ckVideoQuality

Format Method
XML app:ckVideoQuality="max480p"
Java cameraView.setVideoQuality(CameraKit.Constants.VIDEO_QUALITY_480P);

Possible values:

  • max480p, VIDEO_QUALITY_480P
  • max720p, VIDEO_QUALITY_720P
  • max1080p, VIDEO_QUALITY_1080P
  • max2160p, VIDEO_QUALITY_2160P
  • lowest, VIDEO_QUALITY_LOWEST
  • highest, VIDEO_QUALITY_HIGHEST
  • qvga, VIDEO_QUALITY_QVGA

Values: max480p, max720p, max1080p, max2160p, lowest, highest, qvga

ckVideoBitRate

Format Method
XML app:ckVideoBitRate="100"
Java cameraView.setVideoBitrate(100);

Possible values:

  • Values: int [0, MAX_INT]

Video bit rate is the video recording bit rate in bits per second


Automatic Permissions Behavior

You can handle permissions yourself in whatever way you want, but if you make a call to CameraView.start() without the android.permission.CAMERA permission, an exception would normally be thrown and your app would crash.

With CameraKit, we will automatically prompt for the android.permission.CAMERA permission if it's not available. If you want to handle it yourself, just make sure you don't call CameraView.start() until you acquire the permissions.

Dynamic Sizing Behavior

You can setup the CameraView dimensions however you want. When your dimensions don't match the aspect ratio of the internal preview surface, the surface will be cropped minimally to fill the view. The behavior is the same as the android:scaleType="centerCrop" on an ImageView.

adjustViewBounds

You can use a mix of a fixed dimension (a set value or match_parent) as well as wrap_content. When you do this ensure that you set android:adjustViewBounds="true" on the CameraView.

When you do this the dimension set to wrap_content will automatically align with the true aspect ratio of the preview surface. In this case the whole preview will be visible with no cropping.

Events

Be sure to set up a CameraListener instance to react to different camera events.

camera.setCameraListener(new CameraListener() {

    @Override
    public void onCameraOpened() {
        super.onCameraOpened();
    }

    @Override
    public void onCameraClosed() {
        super.onCameraClosed();
    }

    @Override
    public void onPictureTaken(byte[] picture) {
        super.onPictureTaken(picture);
    }

    @Override
    public void onVideoTaken(File video) {
        super.onVideoTaken(video);
    }

});