要使用Android CameraX库初始化相机,请按照以下步骤操作:
dependencies {
implementation 'androidx.camera:camera-core:1.0.0'
implementation 'androidx.camera:camera-camera2:1.0.0'
implementation 'androidx.camera:camera-view:1.0.0'
}
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.front" />
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.camera.core.CameraView
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</layout>
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.ImageAnalysis;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.CameraInfoUnavailableException;
import androidx.camera.core.CameraSelector.Builder;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.core.ImageAnalyzer.AnalyzerResult;
import androidx.camera.core.ImageAnalyzer.AnalyzerResults;
import androidx.camera.core.ImageProxy;
import androidx.camera.core.ImageAnalyzer;
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.camera.