EasyCam is Android Library that lets you easily integrate a camera feature in your app.
Goals of EasyCam's are
- Easy implementation of the camera in the app
- Easy Customization of camera view
This library handles all the logical parts internally and lets you implement a camera view within minutes. In this post, we will see how to integrate EasyCam by calling an Intent and EasyCamFragment - a way to customize your UI as we have handled all logics and memory handling in EasyCamFragment.
Here is the repo Link and Sample
By Intent
How does it work?
EasyCam has Capture and Preview page. The Capture page is where the user has a preview of the camera preview (you can look at the image below). Each UI component on this page is customizable. The preview page contains a preview of the image taken. You can go through the list of images you had captured and delete them if required.
It stores the images taken in the external directory as files and returns in onActivityResult callback.
EasyCam offers the following features
- Screen orientation handling
- Output image orientation handling
- Front and Back camera support
- Flash support
- Single and multiple photoshoot mode
- Set minimum and maximum count for multiple shoot mode
- Preview of taken photos
- Manual focus
- Live preview in full screen or fit the aspect ratio
- Delete option in multiple shoot mode
Add the dependency in module Gradle file
implementation 'in.balakrishnan.easycam:easycam:0.0.3-rc5'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0-rc03'
You can trigger the Camera Activity with the following code
Intent intent = new Intent(this, CameraControllerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("inputData", new CameraBundleBuilder()
.setFullscreenMode(false)
.setDoneButtonString("Add")
.setSinglePhotoMode(false)
.setMax_photo(3)
.setManualFocus(true)
.setBucketName(getClass().getName())
.setPreviewEnableCount(true)
.setPreviewIconVisiblity(true)
.setPreviewPageRedirection(true)
.setEnableDone(false)
.setClearBucket(true)
.createCameraBundle());
startActivityForResult(intent, 214);
You will get the result in the onActivityResult callback
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 214) {
if (resultCode == RESULT_OK) {
assert data != null;
list = data.getStringArrayExtra("resultData");
}
}
}
CameraBundleBuilder is a builder class used to configure the Camera View. With simple parameters, you will get the following screen
EasyCam Fragment
EasyCam Fragment contains all logic and configuration required for setting up a Camera View in your app.
To implement a simple camera view in your app. Extend EasyCamFragment
instead of Fragment. There are three abstract functions you need to override.
- getImageThumb() - You can get the thumbnail image of the captured image. The image is Low in size and quality. It is snap from texture view
- getImage() - You can get an Original image using this function. The Image is high in size and quality. It is from Camera Source
- setTextureResource() - You should return the Texture Id in this callback
How to trigger Image capture?
You can trigger image capture using takePicture()
function in EasyCamFragment.
Customization
You can customize the following
- Front and Back Camera selection
- Flash type
- Full-Screen
- Manual Focus
Here is an example
Top comments (0)