@ -52,7 +46,7 @@ Try out all the unique features using the CameraKit Demo from the Google Play st
- Multiple capture methods.
- `METHOD_STANDARD`: an image captured normally using the camera APIs.
- `METHOD_STILL`: a freeze frame of the `CameraView` preview (similar to SnapChat and Instagram) for devices with slower cameras.
- Automatic picture mode determination based on measured speed.
- `METHOD_AUTO`: automatic capture method determination based on measured speed.
- Built-in tap to focus and auto focus.
- Built-in pinch to zoom.
@ -92,37 +86,47 @@ protected void onPause() {
}
```
### Events
### Capturing Images
Make sure you can react to different camera events by setting up a `CameraListener` instance.
To capture an image just call `CameraView.captureImage()`. Make sure you setup a `CameraListener` to handle the image callback.
```java
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);
// Create a bitmap
Bitmap result = BitmapFactory.decodeByteArray(picture, 0, picture.length);
}
});
camera.captureImage();
```
### Capturing Video
To capture video just call `CameraView.startRecordingVideo()` to start, and `CameraView.stopRecordingVideo()` to finish. Make sure you setup a `CameraListener` to handle the video callback.
To capture video just call `CameraView.startRecordingVideo()` to start, and `CameraView.stopRecordingVideo()` to finish. Make sure you setup a `CameraListener` to handle the video callback.
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.
When you use `METHOD_STANDARD` (`camerakit:ckMethod="standard"`), images will be captured using the normal camera API capture method using the shutter.
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`.
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.
When you capture output you can either capture everything - even what is not visible to the user on the `CameraView` - or just the visible preview. See [`ckCropOutput`](#ckcropoutput) above for usage.
When you use `METHOD_SPEED` (`camerakit:ckMethod="speed"`), images will be first be captured using the [standard](#standard) method. If capture consistently takes a long amount of time, the picture mode will fallback to [still](#still) capture.
[Insert GIF]
### `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 make sure you set `android:adjustViewBounds="true"` on the `CameraView`.
### `ckZoom`
[`off`](#off-2) [`pinch`](#pinch)
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.
#### `off`
## Capture Methods
```java
cameraView.setZoom(CameraKit.Constants.ZOOM_OFF);
```
We decided to add multiple capture modes to CameraKit to allow you to give a better image capturing experience to users with slower cameras when appropriate.
When you use `METHOD_STANDARD` (`camerakit:ckMethod="standard"`), images will be captured using the normal camera API capture method using the shutter.
### `ckCropOutput`
[`true`](#true) [`false`](#false)
[Insert GIF]
#### `true`
### Still
```java
cameraView.setCropOutput(true);
```
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.
#### `false`
[Insert GIF]
```java
cameraView.setCropOutput(false);
```
### Auto
- - -
When you use `METHOD_AUTO` (`camerakit:ckMethod="auto"`), images will be first be captured using the [standard](#standard) method. If capture consistently takes a long amount of time, the picture mode will fallback to [still](#still) capture.
### `ckJpegQuality`
[Insert GIF]
```java
cameraView.setJpegQuality(100);
```
- - -
## Focus
## Automatic Permissions Behavior
Along with the always on auto-focus, you can enable tap to focus in your `CameraView`. See [`ckFocus`](#ckFocus) for usage. You have the option of having it on with a visible focus marker, on with no marker, or off.
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.
[Insert GIF]
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.
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`.
![Dynamic sizing gif](.repo/sizing.gif)
### `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 make sure 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
Make sure you can react to different camera events by setting up a `CameraListener` instance.
Toast.makeText(MainActivity.this,"Tap to focus is"+(checkedId==R.id.modeTapToFocusOff?" off!":(checkedId==R.id.modeTapToFocusVisible)?" on and visible!":" on and invisible!"),Toast.LENGTH_SHORT).show();
}
};
@OnClick(R.id.widthUpdate)
voidwidthUpdateClicked(){
if(widthUpdate.getAlpha()>=1){
@ -322,9 +292,20 @@ public class MainActivity extends AppCompatActivity {
cameraLayoutParams.width=width;
cameraLayoutParams.height=height;
camera.addOnLayoutChangeListener(this);
camera.setLayoutParams(cameraLayoutParams);
Toast.makeText(this,(updateWidth&&updateHeight?"Width and height":updateWidth?"Width":"Height")+" updated!",Toast.LENGTH_SHORT).show();