hazrmard/Android-Camera2-Library


Simple library that allows you to display preview and take pictures easily with callbacks!

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.hazrmard:Android-Camera2-Library:'
	}
	dependencies {
		implementation("com.github.hazrmard:Android-Camera2-Library:")
	}
	<dependency>
	    <groupId>com.github.hazrmard</groupId>
	    <artifactId>Android-Camera2-Library</artifactId>
	    <version></version>
	</dependency>

                            
    libraryDependencies += "com.github.hazrmard" % "Android-Camera2-Library" % ""
        
        

                            
    :dependencies [[com.github.hazrmard/Android-Camera2-Library ""]]
        
        

Readme


Android Camera2 Library

Simple library that allows you to display preview and take pictures easily with callbacks!

Install

Add the following line in your gradle dependencies:

compile 'me.aflak.libraries:ezcam:1.0'

Permission

<uses-permission android:name="android.permission.CAMERA" />

For storing pictures on SD card (optional):

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

In your Activity

EZCam cam = new EZCam(this);
cam.selectCamera(EZCam.FRONT); // or EZCam.BACK
cam.setStopPreviewOnPicture(true);

Callback

cam.setEZCamCallback(new EZCam.EZCamCallback() {
    @Override
    public void onPicture(ImageReader reader) {
        // picture available
        cam.saveImage(reader, "image.jpeg"); // save to internal storage
        cam.saveImage(reader, "image.jpeg", EZCam.EXTERNAL_STORAGE); // OR external storage
    }

    @Override
    public void onError(String message) {
        // error occurred
    }
});

Preview

TextureView textureView = (TextureView)findViewById(R.id.textureView);
textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
    @Override
    public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
        cam.startPreview(surfaceTexture, i, i1);
    }
});

Take picture | stop/resume preview

// take picture
cam.takePicture();

// stop preview
cam.stopPreview();

// resume preview
cam.resumePreview();