kandi X-RAY | android-Camera2Basic Summary
kandi X-RAY | android-Camera2Basic Summary
This repo has been migrated to [github.com/android/camera]. Please check that repo for future updates. Thank you!.
Top functions reviewed by kandi - BETA
- Captures a still picture
- Release the camera focus
- Shows a toast on the UI thread
- Set auto - flash mode on the request
- Resume the view
- Returns the optimal size of the supported sizes
- Configures the required transformation to render the view
- Sets up member variables related to camera data
- Closes the camera
- Stops the active background thread
- Closes the current camera
- Click the view
- Takes a screenshot of an image
- Locks the camera
- This method is called when the camera is created
- Construct a new instance of Camera2BasicFragment
- Run the precapture sequence
- Creates a new camera capture session
- Region > measure
- Called when view is created
- Create image file
- Show error dialog
- On create view
android-Camera2Basic Key Features
android-Camera2Basic Examples and Code Snippets
Trending Discussions on android-Camera2Basic
Camera2 API allows us to specify the thread (passing the
Handler instance) on which we recieve the callbacks containing
CaptureResult etc. We use the information from these callbacks to configure capture session, create capture requests and obtain capture results. However, when the user controls the camera configuration (e.g. focusing, metering) through the UI, he makes it from the main thread. Here we, developers, have two options:
- Use the Camera2 API calls (e.g.
CameraCaptureSession.capture) "directly" from any thread (including
main thread). Here we need to manage the session state and syncrhonize access to the Camera2 API.
- Move all Camera2 API calls to the "CameraThread". Send the message to the "CameraThread" using
Handlerwhenever we need access to Camera2 API. So we will actually use it only from the single thread ("CameraThread").
Please, let me clarify what I mean. Suppose that we created
HandlerThread for Camera2 API callbacks.
ANSWERAnswered 2020-Sep-22 at 22:35
They're both viable. "Better" depends on a bunch of factors such as the size of the codebase, and how many different places in the code will be wanting to use the session and device.
There's some minor overhead in sending the callback to the camera handler thread, plus more boilerplate to write, so for smaller apps, just making calls from whatever thread you're in and synchronizing appropriately works fine.
However, as your app's complexity grows, it starts becoming attractive to keep all interaction with the camera API to a single thread; not just because you don't have to synchronize explicitly, but because it's easier to reason about ownership, the state of the system, and so on, if every interaction with the camera object happens on the same thread. Also, since some of the camera API methods can block for extended time periods, you really don't want to freeze your UI for that long anyway. So sending the calls to another thread is valuable.
So it's a tradeoff of some extra boilerplate + minor overhead vs. inability to centralize camera code in one place for simplicity and smoothness.
There are a couple of samples to get the relative rotation from the camera sensor to the current device orientation, e.g. for using it for correcting camera preview or for
But the newest method from the latest official github camera samples works different than older methods (for deprecated camera2 API and method from archived camera2 sample)
Here's my sample code that uses all methods and logs all results, we can see that function
computeRelativeRotationCamera2New returns different result for
Surface.ROTATION_270 display rotation
So what is the correct method to do it?...
ANSWERAnswered 2020-Jul-31 at 07:19
Tested recorded videos with different methods and found out that the newest method from the latest sample is incorrect for landscape video recording, it plays videos upside down
I decided to update old method that uses deprecated camera api to use camera2 api (works for 21+ API) and use it in my project
No vulnerabilities reported
You can use android-Camera2Basic like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the android-Camera2Basic component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Reuse Trending Solutions
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page