ממשק API של תוספי CameraX

‫CameraX מספק Extensions API לגישה לתוספים שיצרני המכשירים הטמיעו במכשירי Android שונים, כמו מצב לילה, HDR, מצב אוטומטי, אפקט בוקה וריטוש פנים. רשימה של מכשירים שתומכים בתוספים מופיעה בקטע מכשירים נתמכים.

ארכיטקטורת התוספים

בתמונה הבאה מוצגת הארכיטקטורה של תוספי המצלמה.

אפליקציית CameraX משתמשת ב-CameraX Extensions API, שמתקשר עם הטמעת התוספים למצלמה של המכשיר.
איור 1. ארכיטקטורת Camera Extensions

אפליקציית CameraX משתמשת בתוספים דרך CameraX Extensions API. ה-API שולח שאילתות לגבי התוספים הזמינים, מגדיר סשן של תוסף המצלמה ומתקשר עם הטמעת תוספי המצלמה של המכשיר.

הפעלת תוסף

כדי להפעיל תוסף:

  1. מקבלים מופע של ExtensionsManager.
  2. בודקים אם מצב התוסף זמין למצלמה באמצעות isExtensionAvailable(). לא כל מכשיר תומך בכל מצב.
  3. יוצרים ExtensionSessionConfig עם מצב התוסף ותרחישי השימוש של Preview ו-ImageCapture.
  4. מקשרים את הגדרת הסשן באמצעות ProcessCameraProvider.bindToLifecycle(). מצב התוסף חל על תרחישי השימוש Preview ו-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);
}

תרחישי שימוש נתמכים

בטבלה הבאה מוצגים תרחישי השימוש שאפשר לקשר כשהתוסף מופעל:

תרחיש שימוש עם תוסף מופעל
Preview, ImageCapture יש תמיכה. מצב התוסף מופעל.
VideoCapture יש תמיכה. ‫VideoCapture מקליט את השידור המשותף של Preview.
ImageAnalysis לא נתמכת.

איך בודקים אם המצלמה תומכת בהגדרת סשן

אם מוסיפים עוד תרחישי שימוש, כמו VideoCapture, או מגדירים תכונות אחרות, צריך לבדוק שהמצלמה תומכת בכל השילוב לפני שמקשרים אותה:

  1. מפעילים את isExtensionAvailable() עם אותו CameraSelector ואותו מצב.
  2. מעבירים את ExtensionSessionConfig אל ProcessCameraProvider.getCameraInfo(). היא מחזירה את ה-CameraInfo של המצלמה ש-bindToLifecycle() יקשר לאותה הגדרה.
  3. קוראים לפונקציה isSessionConfigSupported() ב-CameraInfo הזה.

אם אחת מהבדיקות נכשלת, צריך לקשר SessionConfig רגיל במקום זאת.

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));

החלפה או השבתה של תוסף

כדי לעבור למצב תוסף אחר, צריך להפעיל שוב את bindToLifecycle() עם ExtensionSessionConfig חדש. כדי להשבית תוספים, צריך לקשר SessionConfig רגיל עם אותם תרחישים לדוגמה. אין צורך להפעיל קודם את unbind() או את unbindAll(): הגדרת הסשן שקושרה קודם ותרחישי השימוש שלה מנותקים באופן אוטומטי.

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));

שיפור חוויית הצילום

במצבים מסוימים של התוסף, כמו מצב לילה ו-HDR, עיבוד תמונה סטטית יכול להימשך כמה שניות. כדי לעדכן את המשתמשים בזמן שהם ממתינים, השתמשו בתצוגה מקדימה לאחר הצילום ובהתקדמות הצילום כשהמכשיר תומך בהן:

  • Postview מספק תמונה ברזולוציה נמוכה בשלב מוקדם, שאפשר להציג עד שהתמונה הסופית מוכנה.
  • Capture process progress מדווח על התקדמות העיבוד מ-0 עד 100, ואפשר להציג אותו כאינדיקטור התקדמות.

מפעילים את התצוגה לאחר הצילום באמצעות ImageCapture.Builder.setPostviewEnabled() לפני שמקשרים. אם המצלמה לא תומכת בתצוגה מקדימה לאחר הצילום, לא נוצרת תמונה כזו. אחרי הקישור, משתמשים ב-ImageCapture.getImageCaptureCapabilities() עם CameraInfo של המצלמה המקושרת כדי לבדוק את isPostviewSupported() ואת isCaptureProcessProgressSupported(), ומגדירים את ממשק המשתמש בהתאם.

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);
            }
        });

צילום תמונות ב-Ultra HDR

בחלק מהמכשירים אפשר לצלם תמונות ב-Ultra HDR כשהתוסף מופעל. צריך להגדיר את פורמט הפלט לפני הקישור, והקישור ייכשל אם הפורמט לא נתמך. לכן, קודם צריך לבדוק את התמיכה: אחרי ש-isExtensionAvailable() מחזיר את true, מקבלים את ה-CameraInfo של המצלמה עם התוסף באמצעות getCameraInfo() ו-ExtensionSessionConfig, ואז בודקים אם getSupportedOutputFormats() כולל את OUTPUT_FORMAT_JPEG_ULTRA_HDR.

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));

מעקב אחרי התוסף ושינוי שלו

אחרי הקישור, משתמשים ב-ExtensionsManager.getCameraExtensionsInfo() וב-ExtensionsManager.getCameraExtensionsControl() עם המצלמה המקושרת כדי לעקוב אחרי התוסף ולשנות אותו.

שינוי עוצמת התוסף

אם הפונקציה isExtensionStrengthAvailable() מחזירה את הערך true, מפעילים את הפונקציה setExtensionStrength() עם ערך בין 0 ל-100. הערך 0 לא מחיל עיבוד של תוספים, ו-100 הוא ערך ברירת המחדל. הפרמטר "עוצמה" קובע את המצב. לדוגמה, במצב לילה הוא קובע כמה תמונות ימוזגו ומה תהיה הבהירות של התמונה הסופית. הערך הנוכחי מופיע ב-getExtensionStrength().

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);
}

הצגת מצב התוסף הנוכחי

ExtensionMode.AUTO יכול לעבור למצבים כמו "ראיית לילה" או HDR בהתאם לסצנה. אם הפונקציה isCurrentExtensionModeAvailable() מחזירה את הערך true, צריך להשתמש ב-getCurrentExtensionMode() כדי להראות למשתמשים איזה מצב פעיל.

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);
}

הצעה להפעיל את מצב הלילה

האינדיקטור של מצב לילה מאותת לאפליקציה כשסביבת הצילום חשוכה מספיק כדי שהתוסף של מצב לילה יעזור, וכך אתם יכולים להציע למשתמש לעבור אליו. האינדיקטור מדווח כשהמצלמה פועלת בלי תוסף. משתמשים ב-CameraInfo.isNightModeIndicatorSupported() כדי לבדוק את התמיכה, ואז בודקים את CameraInfo.getNightModeIndicator(). כשהערך הוא NightModeIndicator.RECOMMENDED, תוצג הצעה. אם המשתמש מאשר, צריך לקשר ExtensionSessionConfig עם ExtensionMode.NIGHT.

כדי להשתמש באינדיקטור של מצב הלילה, צריך את CameraX מגרסה 1.7.0 ואילך ומכשיר עם Android מגרסה 16 (רמת API‏ 36) ואילך. ‫isNightModeIndicatorSupported() מחזיר את הערך false ברמות API נמוכות יותר.

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));
}

פניות קשורות

ממשק ה-API של תוספי CameraX מוטמע בספרייה camera-extensions. התוספים תלויים במודולים העיקריים של CameraX‏ (core,‏ camera2 ו-lifecycle). צריך להשתמש באותה גרסה לכל הספריות של 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}")
}

מגניב

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}"
}

מעבר מ-API לבחירת מצלמה שהוצא משימוש

‫ExtensionsManager.getExtensionEnabledCameraSelector() הוצא משימוש החל מגרסה CameraX 1.7.0-alpha02. במקום זאת, צריך להשתמש ב-ExtensionSessionConfig, כמו שמוצג בטבלה הבאה:

הוצא משימוש החלפה
getExtensionEnabledCameraSelector(cameraSelector, mode) ExtensionSessionConfig(mode, extensionsManager, useCases)
bindToLifecycle(owner, extensionCameraSelector, preview, imageCapture) bindToLifecycle(owner, cameraSelector, extensionSessionConfig)
getCameraInfo(extensionCameraSelector) getCameraInfo(cameraSelector, extensionSessionConfig)
‫unbindAll(), ואז לקשר שוב כדי להחליף מצבים מקשרים את הגדרת הסשן החדשה. הקישור הקודם מבוטל באופן אוטומטי.

מקורות מידע נוספים

למידע נוסף על CameraX, אפשר לעיין במקורות המידע הבאים.

Codelab

  • תחילת העבודה עם CameraX
  • דוגמת קוד

    קטלוג דוגמאות למצלמה (ראו את הדוגמה לתוספים)

    מקורות מידע נוספים

    תוספים של ספק CameraX

    כלי האימות של CameraX Vendor Extensions