日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > Android >内容正文

Android

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

發(fā)布時(shí)間:2025/3/12 Android 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android平台使用Camera2(5.0+)替代过时的Camera 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(zhuǎn)自: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

創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)

總結(jié)

以上是生活随笔為你收集整理的Android平台使用Camera2(5.0+)替代过时的Camera的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。