Introduction to Android Camere Development (2): Use of Camera2

Introduction to Android Camere Development (2): Use of Camera2

Introduction to Camera2 API

In the previous article "Introduction to Android Camere Development (1): Use of Camera1", we learned how to use the Camera API in Android applications to access the device's camera. However, as Android devices develop and hardware improves, we need to use more powerful and flexible APIs to meet the growing needs. This is the Camera2 API we are going to introduce today.

Camera2 API is a new camera API introduced in Android 5.0 (API 21). It provides comprehensive control over the device camera, including preview, capture, image format, image quality, video recording, etc. Compared with the Camera API, the Camera2 API is more powerful and flexible and can better meet the needs of developers.

This article will introduce how to use Camera2 API to perform camera operations, including preview, photo taking and video recording functions.

Get camera permissions

First, we need to add a camera permission application to the AndroidManifest.xml file so that the application can access the device's camera.

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

A third-party permission application framework is used here, and dependencies are added in build.gradle

implementation 'com.github.getActivity:XXPermissions:18.0'

Apply for permission in Activity and give corresponding prompts when the user refuses.

Guess you like

Origin blog.csdn.net/qq_35350654/article/details/132484325