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