自 2025 年 3 月 27 日起,我們建議您使用 android-latest-release
而非 aosp-main
建構及貢獻 AOSP。詳情請參閱「Android 開放原始碼計畫變更」。
相機散景
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
相機散景效果是一種淺景深度效果,透過模糊處理畫面中的部分畫面,讓畫面模糊不清。在行動裝置的相機上,系統會使用從兩部相機的立體視覺或單一相機的雙光電二極體 (PD) 取得的深度資訊,產生散景效果。
自 Android 11 起,Android 平台支援 bokeh 實作,並提供 API,讓第三方應用程式可使用這項功能。
實作
如要在裝置上使用相機散景功能,請按照下列步驟操作:
廣告 ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_MAX_SIZES
:
這個標記的格式為三個整數元組陣列,每個元組的格式為 {mode, maxWidth, maxHeight}
。除了 {ANDROID_CONTROL_EXTENDED_SCENE_MODE_DISABLED, 0, 0}
之外,相機 HAL 也必須列出 ANDROID_CONTROL_EXTENDED_SCENE_MODE_BOKEH_STILL_CAPTURE
和 ANDROID_CONTROL_EXTENDED_SCENE_MODE_BOKEH_CONTINUOUS
模式 (或兩者皆列出),並附上相應的最大串流大小。
廣告 ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_ZOOM_RATIO_RANGES
:
這個標記的格式為 {minZoomRatio, maxZoomRatio}
陣列,其中包含已啟用擴充場景模式的所有縮放比例範圍,順序與 ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_MAX_SIZES
相同。如果縮放範圍為 [1.0, 1.0]
,表示系統不支援縮放。
在 ANDROID_CONTROL_AVAILABLE_MODES
中填入 ANDROID_CONTROL_USE_EXTENDED_SCENE_MODE
。
應用程式必須將 ANDROID_CONTROL_MODE
設為 ANDROID_CONTROL_USE_EXTENDED_SCENE_MODE
,並將 ANDROID_CONTROL_EXTENDED_SCENE_MODE
設為支援的擴充場景模式,才能觸發散景效果功能。請注意,實作 bokeh 可能會因立體運算而導致額外的記憶體用量。
如果無法為每個影格套用支援的擴充場景模式,且啟用/停用時會導致意外延遲,請在 ANDROID_REQUEST_AVAILABLE_SESSION_KEYS
中加入 ANDROID_CONTROL_EXTENDED_SCENE_MODE
。同時,請實作 ICameraDeviceSession::isReconfigurationRequired()
方法,避免針對不需要重新設定的擴充場景模式進行重新設定。
驗證
如要驗證裝置上的 bokeh 功能,請執行下列 CTS、VTS 和 CTS Verifier 測試:
CtsCameraTestCases
VtsHalCameraProviderV2_4TargetTest
- CTS 驗證器中的
CameraBokehTest
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# Camera bokeh is a shallow depth-of-field effect created by blurring out parts of\na scene so that they're not in focus. On cameras on mobile devices, bokeh is\nachieved using depth information acquired from the stereo vision from two\ncameras or from dual photodiodes (PDs) of a single camera.\n\nStarting from Android 11, the Android platform\nsupports bokeh implementations and provides APIs to make the feature available\nto third-party apps.\n\nImplementation\n--------------\n\nTo make the camera bokeh feature available on your device, do the following:\n\n- Advertise `ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_MAX_SIZES`:\n\n This tag is in the format of a three-integer tuple array, with each tuple\n in the format of `{mode, maxWidth, maxHeight}`. In addition to\n `{ANDROID_CONTROL_EXTENDED_SCENE_MODE_DISABLED, 0, 0}`, the camera HAL must\n also list one or both of the\n `ANDROID_CONTROL_EXTENDED_SCENE_MODE_BOKEH_STILL_CAPTURE` and\n `ANDROID_CONTROL_EXTENDED_SCENE_MODE_BOKEH_CONTINUOUS` modes with their\n corresponding maximum streaming sizes.\n- Advertise\n `ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_ZOOM_RATIO_RANGES`:\n\n This tag is in the format of a `{minZoomRatio, maxZoomRatio}` array,\n which contains all the zoom ratio ranges for an enabled extended scene\n mode, in the same order as in\n `ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_MAX_SIZES`. A zoom range of\n `[1.0, 1.0]` means that zoom isn't supported.\n- Populate `ANDROID_CONTROL_USE_EXTENDED_SCENE_MODE` in\n `ANDROID_CONTROL_AVAILABLE_MODES`.\n\nFor an app to trigger the bokeh feature, the app must set `ANDROID_CONTROL_MODE`\nto `ANDROID_CONTROL_USE_EXTENDED_SCENE_MODE` and\n`ANDROID_CONTROL_EXTENDED_SCENE_MODE` to one of supported extended scene modes.\nNote that implementing bokeh might lead to extra memory consumption because of\nstereo computation.\n\nIf a supported extended scene mode can't be applied per frame and results in\nunexpected delays when enabled/disabled, include\n`ANDROID_CONTROL_EXTENDED_SCENE_MODE` in\n`ANDROID_REQUEST_AVAILABLE_SESSION_KEYS`. At the same time, implement the\n`ICameraDeviceSession::isReconfigurationRequired()` method to avoid\nreconfiguration for extended scene modes that don't require reconfiguration.\n\nValidation\n----------\n\nTo validate the bokeh feature on your device, run the following CTS, VTS, and\nCTS Verifier tests:\n\n- `CtsCameraTestCases`\n- `VtsHalCameraProviderV2_4TargetTest`\n- `CameraBokehTest` in CTS Verifier"]]