透過集合功能整理內容
你可以依據偏好儲存及分類內容。
CameraX 是一種 Jetpack 程式庫,旨在簡化相機應用程式的開發作業。如要建構新的應用程式,建議先從 CameraX 開始著手。這個程式庫提供一致且易於使用的 API,適用於大多數 Android 裝置,而且具備 Android 5.0 (API 級別 21) 的回溯相容性。如果要從 Camera1 遷移應用程式,請參閱「從 Camera1 到 CameraX 的遷移指南」。
主要優點
CameraX 可透過下列幾個主要方式改善開發人員體驗。
相容於多種裝置
CameraX 支援搭載 Android 5.0 (API 級別 21) 以上版本的裝置,占現有 Android 裝置的 98% 以上。
使用方便
CameraX 以用途為主軸,讓您能專心處理需要完成的工作,無須管理個別裝置的細微差異,並支援下列幾種最常見的相機用途:
- 預覽:在螢幕上查看圖片。
- 相片分析:流暢存取緩衝區,以便用於演算法 (例如傳送至 ML Kit)。
- 相片拍攝:儲存圖片。
- 影片拍攝:儲存影片和音訊。
跨裝置的一致性
圖 2. 自動化 CameraX 測試研究室可確保多種裝置類型與製造商的 API 體驗一致。
維持相機行為的一致性並非易事,必須考慮長寬比、螢幕方向、旋轉、預覽尺寸和圖片大小等因素,而 CameraX 讓這些基本行為能夠順利運作。
我們負責維護的自動化 CameraX 測試研究室,可測試多種裝置及所有作業系統版本 (Android 5.0 以上) 的相機行為。這些測試會持續執行,找出各種問題並加以修正。
相機擴充功能
圖 3:使用 CameraX 的散景 (肖像) 效果拍攝的相片。
CameraX 提供選用的 Extensions API,您只須加上兩行程式碼,就能使用與裝置原生相機應用程式相同的功能與特色。
這些擴充功能包括散景 (肖像)、高動態範圍 (HDR)、夜間模式和修容功能,但前提是裝置必須支援這些功能。
個案研究
如要瞭解 CameraX 如何簡化 Monzo 的開發作業,請參閱個案研究。
說明文件
其他資源
如要進一步瞭解 CameraX,請參閱下列其他資源。
程式碼研究室
開始使用 CameraX
程式碼範例
CameraX 範例應用程式
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-26 (世界標準時間)。
[null,null,["上次更新時間:2025-07-26 (世界標準時間)。"],[],[],null,["# CameraX overview\nPart of [Android Jetpack](/jetpack).\n=====================================================\n\nCameraX is a Jetpack library, built to help make camera app development easier.\nFor new apps, we recommend starting with CameraX. It provides a consistent,\neasy-to-use API that works across the vast majority of Android devices, with\nbackward-compatibility to Android 5.0 (API level 21). If you're migrating an app\nfrom Camera1, see our\n[Camera1 to CameraX migration guide](/training/camerax/camera1-to-camerax). \n[Get started with CameraX](https://codelabs.developers.google.com/codelabs/camerax-getting-started)\n\nPrimary benefits\n----------------\n\nCameraX improves the developer experience in several key ways.\n\n### Broad device compatibility\n\nCameraX supports devices running\n[Android 5.0 (API level 21)](/about/versions/lollipop) and higher,\nrepresenting over 98% of existing Android devices.\n\n### Ease of use\n\nCameraX emphasizes use cases, which allow you to focus on the task you need\nto get done instead of managing device-specific nuances.\nMost common camera use cases are supported:\n\n- [Preview](/training/camerax/preview): View an image on the display.\n- [Image analysis](/training/camerax/analyze): Access a buffer seamlessly for use in your algorithms, such as to pass to ML Kit.\n- [Image capture](/training/camerax/take-photo): Save images.\n- [Video capture](/training/camerax/video-capture): Save video and audio.\n\n### Consistency across devices\n\n**Figure 2.** Automated CameraX test lab ensures a consistent API\nexperience across many device types and manufacturers.\n\nMaintaining consistent camera behavior is hard. You have to consider\naspect ratio, orientation, rotation, preview size, and image size.\nWith CameraX, these basic behaviors just work.\n\nWe maintain an automated CameraX test lab that tests a variety of camera\nbehaviors across [a range of devices](/training/camerax/devices)\nand all operating system versions since Android 5.0. These tests\nrun on an ongoing basis to identify and fix a wide range of issues.\n\n### Camera extensions\n\n**Figure 3.** An image captured with\nthe bokeh (portrait) effect using CameraX.\n\nCameraX has an optional [Extensions](/training/camerax/extensions-api) API that\nallows you to access the same features and capabilities as a device's native\ncamera app with as few as two lines of code.\n\nExtensions include bokeh (portrait), high dynamic range (HDR),\nnight mode, and face retouching, all of which require device support.\n\n### Case study\n\nTo see how CameraX has simplified development for Monzo,\nsee [their case study](/stories/apps/monzo-camerax).\n\nDocumentation\n-------------\n\n- [CameraX architecture](/training/camerax/architecture)\n- [Configuration options](/training/camerax/configuration)\n- [Implement a preview](/training/camerax/preview)\n- [Image analysis](/training/camerax/analyze)\n- [Image capture](/training/camerax/take-photo)\n- [Video capture](/training/camerax/video-capture)\n- [Camera extensions](/training/camerax/extensions-api)\n- [Transform output](/training/camerax/transform-output)\n- [Use case rotations](/training/camerax/orientation-rotation)\n- [Lab-tested devices](/training/camerax/devices)\n\nAdditional resources\n--------------------\n\nTo learn more about CameraX, consult the following additional resources.\n\n### Codelab\n\n\n- [Getting Started with CameraX](https://codelabs.developers.google.com/codelabs/camerax-getting-started)\n\n### Code sample\n\n- \n- [CameraX sample apps](https://github.com/android/camera-samples/)"]]