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