Android平台使用Camera2(5.0+)替代过时的Camera

Android平台使用Camera2(5.0+)替代过时的Camera,第1张

概述转自:https://forums.developer.amazon.com/articles/2707/using-camera2-to-replace-deprecated-camera-api.htmlFromAndroid5.0(APILevel21)thenewCamera2API(android.hardware.Camera2)isintroducedwhichnowgivesfullmanualcontroloverAndroiddevicecam

转自:https://forums.developer.amazon.com/articles/2707/using-camera2-to-replace-deprecated-camera-api.html

From AndroID 5.0(API Level 21) the new Camera2 API(androID.harDWare.Camera2) is introduced which Now gives full manual control over AndroID device cameras. With prevIoUs Camera API(androID.harDWare.Camera), manual controls for the camera were only accessible by making changes to OS and existing APIs which wasn't frIEndly. The old Camera API (androID.harDWare.Camera) is Now deprecated on AndroID 5.0 and recommended to use Camera2 API for future apps.

Pre-L Camera API - limited access to streaming image data limited information about camera state No manual capture control

Camera2 API - Supports 30fps full resolution with burst mode Supports change on manual camera settings between frame capture Supports RAW image capture Supports Zero Shutter Lag & MovIE Snapshot Supports setting other manual camera device controls including level of Noise Cancelling

Resolution

Basic usage of camera is divIDed with 5 main parts(CameraManager,CameraDevice,CameraCaptureSession,CaptureRequest,CaptureResult)

CameraManager - ProvIDes interfaces for iterating, Listing and connecting to CameraDevices http://developer.android.com/reference/android/hardware/camera2/CameraManager.html

CameraDevice - Representation of a single camera connected to an AndroID device http://developer.android.com/reference/android/hardware/camera2/CameraDevice.html

CameraCaptureSession - ProvIDes set of target output surfaces(TextureVIEw,MediaRecorder,MediaCodec,ImageReader,RenderScriptAllocation) http://developer.android.com/reference/android/hardware/camera2/CameraCaptureSession.html

CaptureRequest - Settings and outputs needed to capture a single image from the camera device Create request builder by predefined templates(TEMPLATE_PREVIEW, TEMPLATE_RECORD, TEMPLATE_STILL_CAPTURE, TEMPLATE_VIDEO_SNAPSHOT, TEMPLATE_MANUAL) This requests are given to capture or setRepeatingRequest to capture images from the camera http://developer.android.com/reference/android/hardware/camera2/CaptureRequest.html

CaptureResult - Results of a single image capture from the image sensorhttp://developer.android.com/reference/android/hardware/camera2/CaptureResult.html

For specifics, you should go through the Camera2 Package Summary page. http://developer.android.com/reference/android/hardware/camera2/package-summary.html

Also there is a great introductory vIDeo by Google Developer Advocate on YouTube that explains the changes on Camera2 API: DevBytes: AndroID L Developer PrevIEw - Camera2 API.

https://www.youtube.com/watch?v=Xtp3tH27OFs

You will need to remember that all features on Camera2 API are not always available on AndroID device cameras. It all depends on the camera device. In order to check that, use Cameracharacteristics to retrIEve camera device feature supported information. characteristics.get(Cameracharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL);

The results will be returned within 3 flavors of camera functionality with the order of FulL > liMITED > LEGACY:

INFO_SUPPORTED_HARDWARE_LEVEL_FulL - Full harDWare level support which allows high resolution capture with support to full manual control. When this is returned, image capture with burst mode and new features will be available.

https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#INFO_SUPPORTED_HARDWARE_LEVEL

INFO_SUPPORTED_HARDWARE_LEVEL_liMITED - A liMITED device may have some or none of the FulL characteristics. Some features are not part of any particular harDWare level or capability and must be querIEd separately.

https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#INFO_SUPPORTED_HARDWARE_LEVEL

INFO_SUPPORTED_HARDWARE_LEVEL_LEGACY - Cameras on all devices support at least this level. This is the same level as the old Camera API which got deprecated.

https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics.html#INFO_SUPPORTED_HARDWARE_LEVEL

Although it is recommended to use Camera2 API for future app development, it is only available for usage from Lollipop(API Level 21). It is unlikely that the Camera2 API will backport to the earlIEr versions of AndroID, so you will need to keep using the Camera API(androID.harDWare.Camera) until minSdkVersion rises to 21 or higher. You can make the app distinguish which camera API to use by the following code.

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LolliPOP) {     // your code using Camera API here - is between 1-20} else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LolliPOP) {     // your code using Camera2 API here - is API 21 or higher}

Keywords: Camera, Deprecated methods, Camera2

总结

以上是内存溢出为你收集整理的Android平台使用Camera2(5.0+)替代过时的Camera全部内容,希望文章能够帮你解决Android平台使用Camera2(5.0+)替代过时的Camera所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1036861.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存