I am reading the code about Android Camera2 APIs from here: https://github.com/googlesamples/android-Camera2Basic
And it is confusing in this lines: https://github.com/googlesamples/android-Camera2Basic/blob/master/Application/src/main/java/com/example/android/camera2basic/Camera2BasicFragment.java#L570-L574
that the previewRequest builder only add surface, which is the TextureView to show, as target. But the following line actually add both as the targets. As I understand, this should not fire the "OnImageAvailable" Lisenter during preview, no? So why this add the imagereader's surface here?
I tried to removed this imagereader's surface here but got error when I really want to capture an image.....
SOOO CONFUSING!!!
Camera2 is the latest low-level Android camera package and replaces the deprecated Camera class. Camera2 provides in-depth controls for complex use cases, but requires you to manage device-specific configurations.
prop in the /system partition of your Android device, you can enable the Camera2 API functionality. First you'll need a rooted phone, and a method of editing your build. prop file. You can either use a root file explorer app (like ES Explorer) to navigate to the /system partition on your phone and open build.
Full: These devices support all of the major capabilities of Camera API2 and must use Camera HAL 3.2 or higher and Android 5.0 or higher. Level_3: These devices support YUV reprocessing and RAW image capture, along with additional output stream configurations on top of full Camera2 API support.
Now the question arises – how can you check if your Android device supports Camera2 API? Well, all you need to do is download a simple app called 'Camera2 API probe' from the Google Play Store and run it. The app gives detailed info about both the rear and front camera sensors of your Android phone.
You need to declare all output Surface
s that image data might be sent to at the time you create a CameraCaptureSession
. This is just the way the framework is designed.
Whenever you create a CaptureRequest
, you add a (list of) target output Surface
(s). This is where the image data from the captured frame will go- it may be a Surface
associated with a TextureView
for displaying, or with an ImageReader
for saving, or with an Allocation
for processing, etc. (A Surface
is really just a buffer which can take the data output by the camera. The type of object that buffer is associated with determines how you can access/work with the data.)
You don't have to send the data from each frame to all registered Surface
s, but it has to be sent to a subset of them. You can't add a Surface
as a target to a CaptureRequest
if it wasn't registered with the CameraCaptureSession
when it was created. Well, you can, but passing it to the session will cause a crash, so don't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With