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