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.omaflak:Android-Camera2-Library:'
}
dependencies {
implementation("com.github.omaflak:Android-Camera2-Library:")
}
<dependency>
<groupId>com.github.omaflak</groupId>
<artifactId>Android-Camera2-Library</artifactId>
<version></version>
</dependency>
libraryDependencies += "com.github.omaflak" % "Android-Camera2-Library" % ""
:dependencies [[com.github.omaflak/Android-Camera2-Library ""]]
EZCam is an Android library that simplifies the use of Camera 2 API for a basic usage.
Add the following line in your gradle dependencies :
compile 'me.aflak.libraries:ezcam:X.X'
Or if you use Maven :
<dependency>
<groupId>me.aflak.libraries</groupId>
<artifactId>ezcam</artifactId>
<version>X.X</version>
<type>pom</type>
</dependency>
Important : The TextureView must be in a FrameLayout.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextureView
android:id="@+id/textureView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
EZCam cam = new EZCam(Context);
String id = cam.getCamerasList().get(CameraCharacteristics.LENS_FACING_BACK); // should check if LENS_FACING_BACK exist before calling get()
cam.selectCamera(id);
cam.setCameraCallback(new EZCamCallback() {
@Override
public void onCameraReady() {
// triggered after cam.open(...)
// you can set capture settings for example:
cam.setCaptureSetting(CaptureRequest.COLOR_CORRECTION_ABERRATION_MODE, CameraMetadata.COLOR_CORRECTION_ABERRATION_MODE_HIGH_QUALITY);
cam.setCaptureSetting(CaptureRequest.CONTROL_EFFECT_MODE, CameraMetadata.CONTROL_EFFECT_MODE_NEGATIVE);
// then start the preview
cam.startPreview();
}
@Override
public void onPicture(Image image) {
File file = new File(getFilesDir(), "image.jpg"); // internal storage
File file = new File(getExternalFilesDir(null), "image.jpg") // external storage, need permissions
EZCam.saveImage(image, file);
}
@Override
public void onError(String message) {
// all errors will be passed through this methods
}
@Override
public void onCameraDisconnected() {
// camera disconnected
}
});
cam.open(CameraDevice.TEMPLATE_PREVIEW, textureView); // needs Manifest.permission.CAMERA
cam.takePicture();
@Override
protected void onDestroy() {
cam.close();
super.onDestroy();
}