xref: /aosp_15_r20/developers/build/prebuilts/gradle/Camera2Basic/README.md (revision d353a188ca6ec4b5eba25b5fbd7bcb8ce61322fb)
1*d353a188SXin Li
2*d353a188SXin LiAndroid Camera2Basic Sample
3*d353a188SXin Li===================================
4*d353a188SXin Li
5*d353a188SXin LiThis sample demonstrates how to use basic functionalities of Camera2
6*d353a188SXin LiAPI. You can learn how to iterate through characteristics of all the
7*d353a188SXin Licameras attached to the device, display a camera preview, and take
8*d353a188SXin Lipictures.
9*d353a188SXin Li
10*d353a188SXin LiIntroduction
11*d353a188SXin Li------------
12*d353a188SXin Li
13*d353a188SXin LiThe [Camera2 API][1] provides an interface to individual camera
14*d353a188SXin Lidevices connected to an Android device. It replaces the deprecated
15*d353a188SXin LiCamera class.
16*d353a188SXin Li
17*d353a188SXin LiUse [getCameraIdList][2] to get a list of all the available
18*d353a188SXin Licameras. You can then use [getCameraCharacteristics][3] and find the
19*d353a188SXin Libest camera that suits your need (front/rear facing, resolution etc).
20*d353a188SXin Li
21*d353a188SXin LiCreate an instance of [CameraDevice.StateCallback][4] and open a
22*d353a188SXin Licamera. It is ready to start camera preview when the camera is opened.
23*d353a188SXin Li
24*d353a188SXin LiThis sample uses TextureView to show the camera preview. Create a
25*d353a188SXin Li[CameraCaptureSession][5] and set a repeating [CaptureRequest][6] to it.
26*d353a188SXin Li
27*d353a188SXin LiStill image capture takes several steps. First, you need to lock the
28*d353a188SXin Lifocus of the camera by updating the CaptureRequest for the camera
29*d353a188SXin Lipreview. Then, in a similar way, you need to run a precapture
30*d353a188SXin Lisequence. After that, it is ready to capture a picture. Create a new
31*d353a188SXin LiCaptureRequest and call [capture][7]. Don't forget to unlock the focus
32*d353a188SXin Liwhen you are done.
33*d353a188SXin Li
34*d353a188SXin Li[1]: https://developer.android.com/reference/android/hardware/camera2/package-summary.html
35*d353a188SXin Li[2]: https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraIdList()
36*d353a188SXin Li[3]: https://developer.android.com/reference/android/hardware/camera2/CameraManager.html#getCameraCharacteristics(java.lang.String)
37*d353a188SXin Li[4]: https://developer.android.com/reference/android/hardware/camera2/CameraDevice.StateCallback.html
38*d353a188SXin Li[5]: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html
39*d353a188SXin Li[6]: https://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html
40*d353a188SXin Li[7]: https://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html#capture(android.hardware.camera2.CaptureRequest, android.hardware.camera2.CameraCaptureSession.CaptureCallback, android.os.Handler)
41*d353a188SXin Li
42*d353a188SXin LiPre-requisites
43*d353a188SXin Li--------------
44*d353a188SXin Li
45*d353a188SXin Li- Android SDK 27
46*d353a188SXin Li- Android Build Tools v27.0.2
47*d353a188SXin Li- Android Support Repository
48*d353a188SXin Li
49*d353a188SXin LiScreenshots
50*d353a188SXin Li-------------
51*d353a188SXin Li
52*d353a188SXin Li<img src="screenshots/main.png" height="400" alt="Screenshot"/>
53*d353a188SXin Li
54*d353a188SXin LiGetting Started
55*d353a188SXin Li---------------
56*d353a188SXin Li
57*d353a188SXin LiThis sample uses the Gradle build system. To build this project, use the
58*d353a188SXin Li"gradlew build" command or use "Import Project" in Android Studio.
59*d353a188SXin Li
60*d353a188SXin LiSupport
61*d353a188SXin Li-------
62*d353a188SXin Li
63*d353a188SXin Li- Google+ Community: https://plus.google.com/communities/105153134372062985968
64*d353a188SXin Li- Stack Overflow: http://stackoverflow.com/questions/tagged/android
65*d353a188SXin Li
66*d353a188SXin LiIf you've found an error in this sample, please file an issue:
67*d353a188SXin Lihttps://github.com/googlesamples/android-Camera2Basic
68*d353a188SXin Li
69*d353a188SXin LiPatches are encouraged, and may be submitted by forking this project and
70*d353a188SXin Lisubmitting a pull request through GitHub. Please see CONTRIBUTING.md for more details.
71*d353a188SXin Li
72*d353a188SXin LiLicense
73*d353a188SXin Li-------
74*d353a188SXin Li
75*d353a188SXin LiCopyright 2017 The Android Open Source Project, Inc.
76*d353a188SXin Li
77*d353a188SXin LiLicensed to the Apache Software Foundation (ASF) under one or more contributor
78*d353a188SXin Lilicense agreements.  See the NOTICE file distributed with this work for
79*d353a188SXin Liadditional information regarding copyright ownership.  The ASF licenses this
80*d353a188SXin Lifile to you under the Apache License, Version 2.0 (the "License"); you may not
81*d353a188SXin Liuse this file except in compliance with the License.  You may obtain a copy of
82*d353a188SXin Lithe License at
83*d353a188SXin Li
84*d353a188SXin Lihttp://www.apache.org/licenses/LICENSE-2.0
85*d353a188SXin Li
86*d353a188SXin LiUnless required by applicable law or agreed to in writing, software
87*d353a188SXin Lidistributed under the License is distributed on an "AS IS" BASIS, WITHOUT
88*d353a188SXin LiWARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
89*d353a188SXin LiLicense for the specific language governing permissions and limitations under
90*d353a188SXin Lithe License.
91