CameraX cung cấp API Extensions dùng cho việc truy cập vào các tiện ích mà nhà sản xuất thiết bị đã triển khai trên nhiều thiết bị Android, chẳng hạn như Ban đêm, HDR, Tự động, Bokeh và Làm đẹp khuôn mặt. Để biết danh sách các thiết bị hỗ trợ tiện ích, hãy xem bài viết Thiết bị được hỗ trợ.
Cấu trúc tiện ích
Hình ảnh sau đây cho thấy cấu trúc của các tiện ích máy ảnh.
Ứng dụng CameraX sử dụng các tiện ích thông qua CameraX Extensions API (API tiện ích CameraX). API này truy vấn các tiện ích có sẵn, định cấu hình một phiên máy ảnh tiện ích và giao tiếp với quá trình triển khai tiện ích máy ảnh của thiết bị.
Bật tiện ích
Để bật một tiện ích, hãy làm như sau:
- Lấy một thực thể
ExtensionsManager. - Kiểm tra xem chế độ tiện ích có dùng được cho máy ảnh hay không bằng
isExtensionAvailable(). Không phải thiết bị nào cũng hỗ trợ mọi chế độ. - Tạo
ExtensionSessionConfigbằng chế độ tiện ích và các trường hợp sử dụngPreviewvàImageCapture. - Liên kết cấu hình phiên với
ProcessCameraProvider.bindToLifecycle(). Chế độ tiện ích được áp dụng cho các trường hợp sử dụngPreviewvàImageCapture.
Kotlin
suspend fun bindNightMode(
context: Context,
lifecycleOwner: LifecycleOwner,
surfaceProvider: Preview.SurfaceProvider,
) {
val cameraProvider = ProcessCameraProvider.awaitInstance(context)
val extensionsManager =
ExtensionsManager.getInstance(context, cameraProvider)
val cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA
// Not every device supports every mode, and binding a mode that the
// camera doesn't support fails. Check availability first.
val isNightAvailable = extensionsManager.isExtensionAvailable(
cameraSelector, ExtensionMode.NIGHT
)
if (!isNightAvailable) {
// Bind a regular session instead (not shown) so that the camera
// still works on devices without the Night extension.
return
}
val preview = Preview.Builder().build()
preview.setSurfaceProvider(surfaceProvider)
val imageCapture = ImageCapture.Builder().build()
// The session config ties the extension mode to the use cases, so
// CameraX applies Night mode to both Preview and ImageCapture.
val sessionConfig = ExtensionSessionConfig(
ExtensionMode.NIGHT,
extensionsManager,
preview,
imageCapture,
)
cameraProvider.bindToLifecycle(
lifecycleOwner, cameraSelector, sessionConfig
)
}
Java
void bindNightMode(Context context, LifecycleOwner lifecycleOwner,
Preview.SurfaceProvider surfaceProvider) {
Executor mainExecutor = ContextCompat.getMainExecutor(context);
ListenableFuture<ProcessCameraProvider> providerFuture =
ProcessCameraProvider.getInstance(context);
// Both the camera provider and ExtensionsManager initialize
// asynchronously. Bind only after both are ready.
providerFuture.addListener(() -> {
try {
ProcessCameraProvider cameraProvider = providerFuture.get();
ListenableFuture<ExtensionsManager> managerFuture =
ExtensionsManager.getInstanceAsync(
context, cameraProvider);
managerFuture.addListener(() -> {
try {
bindNightModeSession(managerFuture.get(),
cameraProvider, lifecycleOwner,
surfaceProvider);
} catch (ExecutionException | InterruptedException e) {
Log.e(TAG, "Failed to get ExtensionsManager", e);
}
}, mainExecutor);
} catch (ExecutionException | InterruptedException e) {
Log.e(TAG, "Failed to get the camera provider", e);
}
}, mainExecutor);
}
void bindNightModeSession(ExtensionsManager extensionsManager,
ProcessCameraProvider cameraProvider,
LifecycleOwner lifecycleOwner,
Preview.SurfaceProvider surfaceProvider) {
CameraSelector cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA;
// Not every device supports every mode, and binding a mode that the
// camera doesn't support fails. Check availability first.
if (!extensionsManager.isExtensionAvailable(
cameraSelector, ExtensionMode.NIGHT)) {
// Bind a regular session instead (not shown) so that the camera
// still works on devices without the Night extension.
return;
}
Preview preview = new Preview.Builder().build();
preview.setSurfaceProvider(surfaceProvider);
ImageCapture imageCapture = new ImageCapture.Builder().build();
// The session config ties the extension mode to the use cases, so
// CameraX applies Night mode to both Preview and ImageCapture.
ExtensionSessionConfig sessionConfig = new ExtensionSessionConfig(
ExtensionMode.NIGHT, extensionsManager, preview, imageCapture);
cameraProvider.bindToLifecycle(
lifecycleOwner, cameraSelector, sessionConfig);
}
Trường hợp sử dụng được hỗ trợ
Bảng sau đây cho biết những trường hợp sử dụng mà bạn có thể liên kết khi bật tiện ích:
| Trường hợp sử dụng | Khi bật tiện ích |
|---|---|
Preview, ImageCapture |
Được hỗ trợ. Chế độ tiện ích đã được áp dụng. |
VideoCapture |
Được hỗ trợ. VideoCapture ghi lại luồng Preview được chia sẻ. |
ImageAnalysis |
Không được hỗ trợ. |
Kiểm tra xem máy ảnh có hỗ trợ cấu hình phiên hay không
Nếu bạn thêm các trường hợp sử dụng khác, chẳng hạn như VideoCapture hoặc đặt các tính năng khác, hãy kiểm tra để đảm bảo máy ảnh hỗ trợ toàn bộ tổ hợp trước khi bạn liên kết:
- Gọi
isExtensionAvailable()bằng cùng mộtCameraSelectorvà chế độ. - Truyền
ExtensionSessionConfigđếnProcessCameraProvider.getCameraInfo(). Hàm này trả vềCameraInfocủa camera màbindToLifecycle()sẽ liên kết cho cấu hình đó. - Gọi
isSessionConfigSupported()trênCameraInfođó.
Nếu một trong hai bước kiểm tra không thành công, hãy liên kết một SessionConfig thông thường.
Kotlin
fun createSessionConfig(
mode: Int,
vararg useCases: UseCase,
): SessionConfig {
// getCameraInfo() throws if no camera matches the extension, so check
// that the mode is available first.
if (extensionsManager.isExtensionAvailable(cameraSelector, mode)) {
val extensionConfig =
ExtensionSessionConfig(mode, extensionsManager, *useCases)
// Check the camera that would actually be bound for this config,
// and verify that it supports these use cases together with the
// extension, for example VideoCapture.
if (cameraProvider.getCameraInfo(cameraSelector, extensionConfig)
.isSessionConfigSupported(extensionConfig)
) {
return extensionConfig
}
}
// The same use cases can still run in a regular session, so the app
// keeps working without the extension.
return SessionConfig(*useCases)
}
cameraProvider.bindToLifecycle(
lifecycleOwner,
cameraSelector,
createSessionConfig(
ExtensionMode.NIGHT, preview, imageCapture, videoCapture
),
)
Java
SessionConfig createSessionConfig(int mode, UseCase... useCases) {
// getCameraInfo() throws if no camera matches the extension, so check
// that the mode is available first.
if (extensionsManager.isExtensionAvailable(cameraSelector, mode)) {
ExtensionSessionConfig extensionConfig =
new ExtensionSessionConfig(
mode, extensionsManager, useCases);
// Check the camera that would actually be bound for this config,
// and verify that it supports these use cases together with the
// extension, for example VideoCapture.
if (cameraProvider.getCameraInfo(cameraSelector, extensionConfig)
.isSessionConfigSupported(extensionConfig)) {
return extensionConfig;
}
}
// The same use cases can still run in a regular session, so the app
// keeps working without the extension.
return new SessionConfig(useCases);
}
cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector,
createSessionConfig(
ExtensionMode.NIGHT, preview, imageCapture, videoCapture));
Chuyển đổi hoặc tắt tiện ích
Để chuyển sang một chế độ tiện ích khác, hãy gọi lại bindToLifecycle() bằng một ExtensionSessionConfig mới. Để tắt tiện ích, hãy liên kết SessionConfig thông thường với cùng một trường hợp sử dụng. Bạn không cần gọi unbind() hoặc unbindAll() trước: cấu hình phiên được liên kết trước đó và các trường hợp sử dụng của cấu hình này sẽ tự động được huỷ liên kết.
Kotlin
// Binding a new session config unbinds the previous one and its use
// cases, so you don't need to call unbindAll() before switching modes.
cameraProvider.bindToLifecycle(
lifecycleOwner,
cameraSelector,
ExtensionSessionConfig(
ExtensionMode.NIGHT, extensionsManager, preview, imageCapture
),
)
// A regular SessionConfig with the same use cases turns the extension off
// while Preview and ImageCapture keep working.
cameraProvider.bindToLifecycle(
lifecycleOwner,
cameraSelector,
SessionConfig(preview, imageCapture),
)
Java
// Binding a new session config unbinds the previous one and its use
// cases, so you don't need to call unbindAll() before switching modes.
cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector,
new ExtensionSessionConfig(ExtensionMode.NIGHT,
extensionsManager, preview, imageCapture));
// A regular SessionConfig with the same use cases turns the extension off
// while Preview and ImageCapture keep working.
cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector,
new SessionConfig(preview, imageCapture));
Cải thiện trải nghiệm chụp ảnh
Một số chế độ tiện ích, chẳng hạn như Ban đêm và HDR, có thể mất vài giây để xử lý ảnh tĩnh. Để thông báo cho người dùng trong khi chờ đợi, hãy sử dụng tiến trình xem sau và chụp khi thiết bị hỗ trợ:
- Postview cung cấp sớm hình ảnh có độ phân giải thấp mà bạn có thể hiển thị cho đến khi hình ảnh cuối cùng sẵn sàng.
- Tiến trình của quá trình chụp báo cáo tiến trình xử lý từ 0 đến 100, bạn có thể hiển thị dưới dạng chỉ báo tiến trình.
Bật chế độ xem sau bằng ImageCapture.Builder.setPostviewEnabled() trước khi liên kết. Nếu máy ảnh không hỗ trợ chế độ xem sau, thì hình ảnh xem sau sẽ không được tạo.
Sau khi liên kết, hãy sử dụng ImageCapture.getImageCaptureCapabilities() với CameraInfo của camera được liên kết để kiểm tra isPostviewSupported() và isCaptureProcessProgressSupported(), đồng thời thiết lập giao diện người dùng cho phù hợp.
Kotlin
// Postview must be configured before binding. If the camera doesn't
// support postview, enabling it has no effect.
val imageCapture = ImageCapture.Builder()
.setPostviewEnabled(true)
.build()
val camera = cameraProvider.bindToLifecycle(
lifecycleOwner,
cameraSelector,
ExtensionSessionConfig(
ExtensionMode.NIGHT, extensionsManager, preview, imageCapture
),
)
// Postview and progress support depend on the extension-enabled camera,
// so query the capabilities of the bound camera.
val capabilities =
ImageCapture.getImageCaptureCapabilities(camera.cameraInfo)
setUpCaptureUi(
showPostview = capabilities.isPostviewSupported,
showProgress = capabilities.isCaptureProcessProgressSupported,
)
// Extension captures can take several seconds. Progress updates and an
// early postview image show users that the capture is being processed.
val results = imageCapture.takePicture(
outputFileOptions,
onCaptureProcessProgressed = { progress -> updateProgress(progress) },
onPostviewBitmapAvailable = { bitmap -> showPostview(bitmap) },
)
// Processing is done. Replace the postview with the final image.
showFinalImage(results.savedUri)
Java
// Postview must be configured before binding. If the camera doesn't
// support postview, enabling it has no effect.
ImageCapture imageCapture = new ImageCapture.Builder()
.setPostviewEnabled(true)
.build();
Camera camera = cameraProvider.bindToLifecycle(
lifecycleOwner, cameraSelector,
new ExtensionSessionConfig(ExtensionMode.NIGHT,
extensionsManager, preview, imageCapture));
// Postview and progress support depend on the extension-enabled camera,
// so query the capabilities of the bound camera.
ImageCaptureCapabilities capabilities =
ImageCapture.getImageCaptureCapabilities(camera.getCameraInfo());
setUpCaptureUi(
capabilities.isPostviewSupported(),
capabilities.isCaptureProcessProgressSupported());
// Extension captures can take several seconds. Progress updates and an
// early postview image show users that the capture is being processed.
imageCapture.takePicture(outputFileOptions, mainExecutor,
new ImageCapture.OnImageSavedCallback() {
@Override
public void onCaptureProcessProgressed(int progress) {
updateProgress(progress);
}
@Override
public void onPostviewBitmapAvailable(@NonNull Bitmap bitmap) {
showPostview(bitmap);
}
@Override
public void onImageSaved(
@NonNull ImageCapture.OutputFileResults results) {
// Processing is done. Replace the postview with the final
// image.
showFinalImage(results.getSavedUri());
}
@Override
public void onError(@NonNull ImageCaptureException exception) {
Log.e(TAG, "Capture failed", exception);
}
});
Chụp ảnh Ultra HDR
Một số thiết bị hỗ trợ chụp ảnh Ultra HDR khi bật tiện ích. Bạn phải đặt định dạng đầu ra trước khi liên kết và quá trình liên kết sẽ không thành công nếu định dạng không được hỗ trợ. Vì vậy, trước tiên, hãy kiểm tra khả năng hỗ trợ: sau khi isExtensionAvailable() trả về true, hãy lấy CameraInfo của camera có bật tiện ích bằng getCameraInfo() và ExtensionSessionConfig, sau đó kiểm tra xem getSupportedOutputFormats() có bao gồm OUTPUT_FORMAT_JPEG_ULTRA_HDR hay không.
Kotlin
// Supported output formats can differ when an extension is enabled, so
// query them from the extension-enabled camera. isExtensionAvailable()
// must have returned true for this selector and mode first; otherwise,
// getCameraInfo() throws.
val extensionCameraInfo = cameraProvider.getCameraInfo(
cameraSelector,
ExtensionSessionConfig(ExtensionMode.NIGHT, extensionsManager),
)
val supportedFormats = ImageCapture
.getImageCaptureCapabilities(extensionCameraInfo)
.supportedOutputFormats
// Binding fails if the output format isn't supported, so request Ultra HDR
// only when the extension-enabled camera supports it.
val imageCapture = ImageCapture.Builder().apply {
if (ImageCapture.OUTPUT_FORMAT_JPEG_ULTRA_HDR in supportedFormats) {
setOutputFormat(ImageCapture.OUTPUT_FORMAT_JPEG_ULTRA_HDR)
}
}.build()
cameraProvider.bindToLifecycle(
lifecycleOwner,
cameraSelector,
ExtensionSessionConfig(
ExtensionMode.NIGHT, extensionsManager, preview, imageCapture
),
)
Java
// Supported output formats can differ when an extension is enabled, so
// query them from the extension-enabled camera. isExtensionAvailable()
// must have returned true for this selector and mode first; otherwise,
// getCameraInfo() throws.
CameraInfo extensionCameraInfo = cameraProvider.getCameraInfo(
cameraSelector,
new ExtensionSessionConfig(ExtensionMode.NIGHT, extensionsManager));
Set<Integer> supportedFormats =
ImageCapture.getImageCaptureCapabilities(extensionCameraInfo)
.getSupportedOutputFormats();
// Binding fails if the output format isn't supported, so request Ultra HDR
// only when the extension-enabled camera supports it.
ImageCapture.Builder builder = new ImageCapture.Builder();
if (supportedFormats.contains(ImageCapture.OUTPUT_FORMAT_JPEG_ULTRA_HDR)) {
builder.setOutputFormat(ImageCapture.OUTPUT_FORMAT_JPEG_ULTRA_HDR);
}
ImageCapture imageCapture = builder.build();
cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector,
new ExtensionSessionConfig(ExtensionMode.NIGHT,
extensionsManager, preview, imageCapture));
Theo dõi và điều chỉnh tiện ích
Sau khi liên kết, hãy sử dụng ExtensionsManager.getCameraExtensionsInfo() và ExtensionsManager.getCameraExtensionsControl() với camera được liên kết để theo dõi và điều chỉnh tiện ích.
Điều chỉnh mức độ mở rộng
Nếu isExtensionStrengthAvailable() trả về true, hãy gọi setExtensionStrength() với giá trị từ 0 đến 100. Giá trị 0 không áp dụng quy trình xử lý tiện ích và 100 là giá trị mặc định. Mức độ kiểm soát của cường độ phụ thuộc vào chế độ; ví dụ: ở chế độ Ban đêm, cường độ kiểm soát số lượng hình ảnh được kết hợp và độ sáng của hình ảnh cuối cùng.
Hãy quan sát getExtensionStrength() để biết giá trị hiện tại.
Kotlin
val camera = cameraProvider.bindToLifecycle(
lifecycleOwner,
cameraSelector,
ExtensionSessionConfig(
ExtensionMode.NIGHT, extensionsManager, preview, imageCapture
),
)
// Pass the bound extension-enabled camera. For a camera without an
// extension, strength isn't available and the control is null.
val extensionsInfo =
extensionsManager.getCameraExtensionsInfo(camera.cameraInfo)
val extensionsControl =
extensionsManager.getCameraExtensionsControl(camera.cameraControl)
// Not every device lets apps adjust the strength, so check support before
// showing a strength control.
if (extensionsInfo.isExtensionStrengthAvailable) {
// For example, connect this to a slider in your UI.
extensionsControl?.setExtensionStrength(50)
}
Java
Camera camera = cameraProvider.bindToLifecycle(
lifecycleOwner, cameraSelector,
new ExtensionSessionConfig(ExtensionMode.NIGHT,
extensionsManager, preview, imageCapture));
// Pass the bound extension-enabled camera. For a camera without an
// extension, strength isn't available and the control is null.
CameraExtensionsInfo extensionsInfo =
extensionsManager.getCameraExtensionsInfo(camera.getCameraInfo());
CameraExtensionsControl extensionsControl =
extensionsManager.getCameraExtensionsControl(
camera.getCameraControl());
// Not every device lets apps adjust the strength, so check support before
// showing a strength control.
if (extensionsInfo.isExtensionStrengthAvailable()
&& extensionsControl != null) {
// For example, connect this to a slider in your UI.
extensionsControl.setExtensionStrength(50);
}
Hiện chế độ tiện ích hiện tại
ExtensionMode.AUTO có thể chuyển sang các chế độ như Ban đêm hoặc HDR tuỳ thuộc vào cảnh. Nếu isCurrentExtensionModeAvailable() trả về true, hãy quan sát getCurrentExtensionMode() để cho người dùng biết chế độ nào đang hoạt động.
Kotlin
val camera = cameraProvider.bindToLifecycle(
lifecycleOwner,
cameraSelector,
ExtensionSessionConfig(
ExtensionMode.AUTO, extensionsManager, preview, imageCapture
),
)
val extensionsInfo =
extensionsManager.getCameraExtensionsInfo(camera.cameraInfo)
// In AUTO mode, the active mode can change with the scene, for example to
// NIGHT in low light. The LiveData is null when the device doesn't report
// the current mode.
if (extensionsInfo.isCurrentExtensionModeAvailable) {
extensionsInfo.currentExtensionMode?.observe(lifecycleOwner) { mode ->
showActiveModeBadge(mode)
}
}
Java
Camera camera = cameraProvider.bindToLifecycle(
lifecycleOwner, cameraSelector,
new ExtensionSessionConfig(ExtensionMode.AUTO,
extensionsManager, preview, imageCapture));
CameraExtensionsInfo extensionsInfo =
extensionsManager.getCameraExtensionsInfo(camera.getCameraInfo());
// In AUTO mode, the active mode can change with the scene, for example to
// NIGHT in low light. The LiveData is null when the device doesn't report
// the current mode.
LiveData<Integer> currentMode = extensionsInfo.getCurrentExtensionMode();
if (extensionsInfo.isCurrentExtensionModeAvailable()
&& currentMode != null) {
currentMode.observe(lifecycleOwner, this::showActiveModeBadge);
}
Đề xuất Chế độ ban đêm
Chỉ báo chế độ ban đêm cho ứng dụng biết khi nào cảnh đủ tối để tiện ích Ban đêm có thể giúp ích, nhờ đó, bạn có thể đề xuất người dùng chuyển sang chế độ này. Chỉ báo được báo cáo khi camera đang chạy mà không có tiện ích. Dùng CameraInfo.isNightModeIndicatorSupported() để kiểm tra khả năng hỗ trợ, sau đó quan sát CameraInfo.getNightModeIndicator(). Khi giá trị là NightModeIndicator.RECOMMENDED, hãy hiển thị một đề xuất.
Nếu người dùng chấp nhận, hãy liên kết ExtensionSessionConfig với ExtensionMode.NIGHT.
Chỉ báo chế độ ban đêm yêu cầu CameraX 1.7.0 trở lên và thiết bị chạy Android 16 (cấp độ API 36) trở lên. isNightModeIndicatorSupported() trả về false ở các cấp độ API thấp hơn.
Kotlin
// The indicator is reported while a regular (non-extension) session is
// running with Preview, so the app can suggest Night mode only when the
// scene is dark enough to need it.
val cameraInfo = camera.cameraInfo
// Don't suggest a mode that the camera can't bind.
val isNightAvailable = extensionsManager.isExtensionAvailable(
cameraSelector, ExtensionMode.NIGHT
)
// If the indicator isn't supported, its value is always UNKNOWN.
if (cameraInfo.isNightModeIndicatorSupported && isNightAvailable) {
cameraInfo.nightModeIndicator.observe(lifecycleOwner) { indicator ->
showNightModeSuggestion(
visible = indicator == NightModeIndicator.RECOMMENDED
)
}
}
fun onNightModeSuggestionAccepted() {
// Binding the extension session config replaces the regular session.
cameraProvider.bindToLifecycle(
lifecycleOwner,
cameraSelector,
ExtensionSessionConfig(
ExtensionMode.NIGHT, extensionsManager, preview, imageCapture
),
)
}
Java
// The indicator is reported while a regular (non-extension) session is
// running with Preview, so the app can suggest Night mode only when the
// scene is dark enough to need it.
CameraInfo cameraInfo = camera.getCameraInfo();
// Don't suggest a mode that the camera can't bind.
boolean isNightAvailable = extensionsManager.isExtensionAvailable(
cameraSelector, ExtensionMode.NIGHT);
// If the indicator isn't supported, its value is always UNKNOWN.
if (cameraInfo.isNightModeIndicatorSupported() && isNightAvailable) {
cameraInfo.getNightModeIndicator().observe(lifecycleOwner,
indicator -> showNightModeSuggestion(
indicator == NightModeIndicator.RECOMMENDED));
}
void onNightModeSuggestionAccepted() {
// Binding the extension session config replaces the regular session.
cameraProvider.bindToLifecycle(lifecycleOwner, cameraSelector,
new ExtensionSessionConfig(ExtensionMode.NIGHT,
extensionsManager, preview, imageCapture));
}
Phần phụ thuộc
API Extensions của CameraX được triển khai trong thư viện camera-extensions.
Các tiện ích phụ thuộc vào các mô-đun lõi của CameraX (core, camera2 và lifecycle). Hãy sử dụng cùng một phiên bản cho tất cả thư viện androidx.camera.
Kotlin
dependencies {
val camerax_version = "1.7.0"
implementation("androidx.camera:camera-core:${camerax_version}")
implementation("androidx.camera:camera-camera2:${camerax_version}")
implementation("androidx.camera:camera-lifecycle:${camerax_version}")
// The CameraX Extensions library
implementation("androidx.camera:camera-extensions:${camerax_version}")
}
Groovy
dependencies {
def camerax_version = "1.7.0"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
implementation "androidx.camera:camera-lifecycle:${camerax_version}"
// The CameraX Extensions library
implementation "androidx.camera:camera-extensions:${camerax_version}"
}
Di chuyển từ API bộ chọn máy ảnh không dùng nữa
ExtensionsManager.getExtensionEnabledCameraSelector()
đã ngừng hoạt động kể từ CameraX 1.7.0-alpha02. Thay vào đó, hãy sử dụng ExtensionSessionConfig như trong bảng sau:
| Không được dùng nữa | Thay thế |
|---|---|
getExtensionEnabledCameraSelector(cameraSelector, mode) |
ExtensionSessionConfig(mode, extensionsManager, useCases) |
bindToLifecycle(owner, extensionCameraSelector, preview, imageCapture) |
bindToLifecycle(owner, cameraSelector, extensionSessionConfig) |
getCameraInfo(extensionCameraSelector) |
getCameraInfo(cameraSelector, extensionSessionConfig) |
unbindAll(), sau đó liên kết lại để chuyển đổi chế độ |
Liên kết cấu hình phiên mới. Dịch vụ trước đó sẽ tự động được huỷ liên kết. |
Tài nguyên khác
Để biết thêm thông tin về CameraX, hãy xem các tài nguyên sau.
Lớp học lập trình
Mã mẫu
Danh mục Mẫu máy ảnh (xem mẫu Tiện ích)
Tài liệu tham khảo khác
Tiện ích của nhà cung cấp CameraX
Công cụ xác thực tiện ích của nhà cung cấp CameraX