项目作者: Badge87

项目描述 :
Helper lib for Android camera2
高级语言: Java
项目地址: git://github.com/Badge87/Camera2Helper.git
创建时间: 2019-03-08T15:25:41Z
项目社区:https://github.com/Badge87/Camera2Helper

开源协议:Other

下载


Camera2 Helper Library

Image

Camera2HelperLib is a simple and lightweight library created to facilitate the use of Android’s Camera2 API.

Including in your project" class="reference-link"> Including in your project

Add jitpack.io to your project’s repositories:

  1. allProjects {
  2. repositories {
  3. google()
  4. // required to find the project's artifacts
  5. // place last
  6. maven { url "https://www.jitpack.io" }
  7. }
  8. }

Add this to your app’s build.gradle dependencies

  1. gradle implementation 'com.danielebachicchi:camera2helperlib:0.0.4'

Usage" class="reference-link"> Usage

Camera Helper is an helper class that handle all the process of the open, close and processing image of the camera. In order to initialize it you have to pass to the constructor:

  • AutoFitTextureView textureView
    The AutoFitTextureView inside the layout.xml of your activity, fragment or view.
  • Activity activity
    The current activity (or fragment activity).
  • ICameraHelperDelegate delegate
    The cameraHelperDelegate (can be the activity/fragment itself or other classes, as you wish).

Usually you create the instance of the CameraHelper during onCreate of your Activity / Fragment.

  1. @Override
  2. protected void onCreate(Bundle savedInstanceState) {
  3. super.onCreate(savedInstanceState);
  4. // Do your work
  5. //retrieve the autofitTextureView inside the layout
  6. AutoFitTextureView autoFitTextureView = findViewById(R.id.textureView);
  7. _cameraHelper = new CameraHelper(autoFitTextureView,this,this);
  8. }

In order for the class to function properly you have to call inside the onPause and onResume the respective methods of the CameraHelper:

  1. @Override
  2. protected void onResume() {
  3. super.onResume();
  4. _cameraHelper.onResume();
  5. }
  6. @Override
  7. protected void onPause() {
  8. super.onPause();
  9. _cameraHelper.onPause();
  10. }

LiveMode

With Live Mode active, you don’t have to manually request to take a picture. CameraHelper will capture a picture in background (outside the main thread) and it communicates it to your delegate.
This mode is helpfull especially for processing in real-time what the camera is seeing, like, for example, barcode or qrcode detect feature.
To enable the liveMode:

  1. //enable the liveMode.
  2. _cameraHelper.set_liveData(true);
  3. //set the interval from one picture to another (in milliseconds).
  4. _cameraHelper.set_liveDataMillisecondDelay(2000);

ICameraHelperDelegate

The delegate has the following method that need to implements:

  1. void onAsyncImageDetected(Image image, CameraHelper.ImageSaver saver);
  2. void onCameraPermissionNotAccepted(CameraHelper helper);
  • onAsyncImageDetected
    When the CameraHelper has an imageAvaiable (after picture request or during liveMode)
  • onCameraPermissionNotAccepted
    When CameraHelper start to initialize but need the CAMERA permission. You can handle the request yourself or call the default method of CameraHelperClass :
  1. @Override
  2. public void onCameraPermissionNotAccepted(CameraHelper helper) {
  3. //you can call this helper method or handle yourself. As you wish :)
  4. helper.requestCameraPermission(getSupportFragmentManager());
  5. }

Requirements

  • Android SDK 23 or higher.

Screenshots



Maintainers

This project is created and mantained by:

License

  1. Copyright 2019 Daniele Bachicchi
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.