Kể từ ngày 27 tháng 3 năm 2025, bạn nên sử dụng android-latest-release
thay vì aosp-main
để xây dựng và đóng góp cho AOSP. Để biết thêm thông tin, hãy xem phần Thay đổi đối với AOSP.
Bokeh của máy ảnh
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Hiệu ứng bokeh của máy ảnh là hiệu ứng độ sâu trường nông được tạo bằng cách làm mờ các phần của cảnh để các phần đó không nằm trong tiêu điểm. Trên máy ảnh trên thiết bị di động, hiệu ứng bokeh được tạo bằng cách sử dụng thông tin chiều sâu thu được từ chế độ xem 3D của hai máy ảnh hoặc từ hai điốt quang (PD) của một máy ảnh.
Kể từ Android 11, nền tảng Android hỗ trợ việc triển khai hiệu ứng bokeh và cung cấp các API để cung cấp tính năng này cho các ứng dụng bên thứ ba.
Triển khai
Để sử dụng tính năng chụp ảnh bokeh trên thiết bị, hãy làm như sau:
Quảng cáo ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_MAX_SIZES
:
Thẻ này có định dạng là mảng gồm 3 bộ dữ liệu số nguyên, trong đó mỗi bộ dữ liệu có định dạng là {mode, maxWidth, maxHeight}
. Ngoài {ANDROID_CONTROL_EXTENDED_SCENE_MODE_DISABLED, 0, 0}
, HAL máy ảnh cũng phải liệt kê một hoặc cả hai chế độ ANDROID_CONTROL_EXTENDED_SCENE_MODE_BOKEH_STILL_CAPTURE
và ANDROID_CONTROL_EXTENDED_SCENE_MODE_BOKEH_CONTINUOUS
với kích thước truyền trực tuyến tối đa tương ứng.
Quảng cáo ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_ZOOM_RATIO_RANGES
:
Thẻ này ở định dạng mảng {minZoomRatio, maxZoomRatio}
, chứa tất cả các phạm vi tỷ lệ thu phóng cho chế độ cảnh mở rộng đã bật, theo thứ tự giống như trong ANDROID_CONTROL_AVAILABLE_EXTENDED_SCENE_MODE_MAX_SIZES
. Phạm vi thu phóng là [1.0, 1.0]
có nghĩa là tính năng thu phóng không được hỗ trợ.
Điền ANDROID_CONTROL_USE_EXTENDED_SCENE_MODE
vào ANDROID_CONTROL_AVAILABLE_MODES
.
Để kích hoạt tính năng bokeh, ứng dụng phải đặt ANDROID_CONTROL_MODE
thành ANDROID_CONTROL_USE_EXTENDED_SCENE_MODE
và ANDROID_CONTROL_EXTENDED_SCENE_MODE
thành một trong các chế độ cảnh mở rộng được hỗ trợ.
Xin lưu ý rằng việc triển khai hiệu ứng bokeh có thể làm tăng mức tiêu thụ bộ nhớ do tính toán âm thanh nổi.
Nếu không thể áp dụng chế độ cảnh mở rộng được hỗ trợ cho mỗi khung hình và dẫn đến tình trạng chậm trễ ngoài dự kiến khi bật/tắt, hãy đưa ANDROID_CONTROL_EXTENDED_SCENE_MODE
vào ANDROID_REQUEST_AVAILABLE_SESSION_KEYS
. Đồng thời, hãy triển khai phương thức ICameraDeviceSession::isReconfigurationRequired()
để tránh định cấu hình lại cho các chế độ cảnh mở rộng không yêu cầu định cấu hình lại.
Xác nhận kết quả
Để xác thực tính năng hiệu ứng bokeh trên thiết bị, hãy chạy các kiểm thử CTS, VTS và CTS Verifier sau:
CtsCameraTestCases
VtsHalCameraProviderV2_4TargetTest
CameraBokehTest
trong Trình xác minh CTS
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[],[],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"]]