A simple library to make it easier for you to embed a camera and surfaceview in an activity in your application.
Gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.hangga:Gampil-Camera:v1.1.2'
}
<id.hangga.gampil.GampilPreview
android:id="@+id/gampilPreview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Initiate object in your java code.
GampilPreview gampilPreview = findViewById(R.id.gampilPreview);
The methods in Gampil you can use.
setFacing(int facing)
Param : facing = Facing.FRONT_CAMERA or Facing.BACK_CAMERA
You can choose front or back camera easily. If you don't call this method, it will use the front camera by default.
Example :
gampilPreview.setFacing(Facing.FRONT_CAMERA); // Default
gampilPreview.setFacing(Facing.BACK_CAMERA);
This is a method for capturing photos from the camera which results in Bitmaps and Files.
takePhoto(int quality, TakePhotoListener takePhotoListener)
Params: quality : (int) Compress bitmap quality. TakePhotoListener : CallBack after takePicture
An example of how to capture a photo is like the code below.
gampilPreview.takePhoto(80, new TakePhotoListener() {
@Override
public void onPhotoTaken(Bitmap bitmap, File file) {
// your code
}
@Override
public void onPhotoError(String message) {
// your code
}
});