DEV Community 👩‍💻👨‍💻

BalaKrishnan
BalaKrishnan

Posted on

## EasyCam

EasyCam is Android Library that lets you easily integrate a camera feature in your app.

Goals of EasyCam's are

  1. Easy implementation of the camera in the app
  2. 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

  1. Screen orientation handling
  2. Output image orientation handling
  3. Front and Back camera support
  4. Flash support
  5. Single and multiple photoshoot mode
  6. Set minimum and maximum count for multiple shoot mode
  7. Preview of taken photos
  8. Manual focus
  9. Live preview in full screen or fit the aspect ratio
  10. 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.

  1. 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
  2. getImage() - You can get an Original image using this function. The Image is high in size and quality. It is from Camera Source
  3. 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

  1. Front and Back Camera selection
  2. Flash type
  3. Full-Screen
  4. Manual Focus

Here is an example

Top comments (0)

Hacktoberfest is happening now!



It is a month-long celebration of open source. For a lot of devs, its their introduction to open source.


Check out the Hacktoberfest tag on DEV to keep up with the latest!