2

我正在尝试构建一个基于 CameraX 的相机应用程序,并希望为相机预览启用 Bokeh (Blur) 效果。这可以通过 CameraX 扩展来完成,但是如何启用它们呢?

我在Android Developer Docs阅读了有关供应商扩展的文章。我尝试重用他们的方法,但示例中显示的类不包含在 CameraXalpha-02

import androidx.camera.extensions.BokehExtender;

void onCreate() {
    // Create a Builder same as in normal workflow.
    ImageCaptureConfig.Builder builder = new ImageCaptureConfig.Builder();

    // Create a Extender object which can be used to apply extension
    // configurations.
    BokehImageCaptureExtender bokehImageCapture = new
            BokehImageCaptureExtender(builder);

    // Query if extension is available (optional).
    if (bokehImageCapture.isExtensionAvailable()) {
        // Enable the extension if available.
        bokehImageCapture.enableExtension();
    }

    // Finish constructing configuration with the same flow as when not using
    // extensions.
    ImageCaptureConfig config = builder.build();
    ImageCapture useCase = new ImageCapture(config);
    CameraX.bindToLifecycle((LifecycleOwner)this, useCase);
}

我预计BokehImageCaptureExtender它将被导入,但看起来它仍然没有提供。而且整个包裹androidx.camera.extensions都不见了。

这些类可以在官方的AndroidX git 存储库中找到,但是如果不导入完整的 AndroidX 项目就很难设置它。

4

3 回答 3

1

Android CameraX 扩展仅存在于版本:“1.0.0-alpha01”中。

降级您的相机版本://Camera Jetpack Library

def camerax_version = "1.0.0-alpha01"
implementation "androidx.camera:camera-core:$camerax_version"
implementation "androidx.camera:camera-camera2:$camerax_version"
implementation "androidx.camera:camera-extensions:$camerax_version"
于 2019-08-13T10:26:33.890 回答
0

google maven https://dl.google.com/dl/android/maven2/index.html上的扩展仍然不可用

参考这个线程, https://stackoverflow.com/a/57177147/11861734

于 2019-07-31T04:20:31.830 回答
0

我刚刚注意到编辑您的问题并在此处查看您显示的代码示例是Java,但您将Kotlin作为标识符。确保您使用的是正确的语言。这可能是问题所在。

这是来自Android 开发者文档的Kotlin示例:

import androidx.camera.extensions.BokehExtender

fun onCreate() {
    // Create a Builder same as in normal workflow.
    val builder = ImageCaptureConfig.Builder()

    // Create a Extender object which can be used to apply extension
    // configurations.
    val bokehImageCapture = BokehImageCaptureExtender.create(builder)

    // Query if extension is available (optional).
    if (bokehImageCapture.isExtensionAvailable()) {
        // Enable the extension if available.
        bokehImageCapture.enableExtension()
    }

    // Finish constructing configuration with the same flow as when not using
    // extensions.
    val config = builder.build()
    val useCase = ImageCapture(config)
    CameraX.bindToLifecycle(this as LifecycleOwner, useCase)
}

这是来自Android Developer Docs的Java示例:

import androidx.camera.extensions.BokehExtender;

void onCreate() {
    // Create a Builder same as in normal workflow.
    ImageCaptureConfig.Builder builder = new ImageCaptureConfig.Builder();

    // Create a Extender object which can be used to apply extension
    // configurations.
    BokehImageCaptureExtender bokehImageCapture = new
            BokehImageCaptureExtender(builder);

    // Query if extension is available (optional).
    if (bokehImageCapture.isExtensionAvailable()) {
        // Enable the extension if available.
        bokehImageCapture.enableExtension();
    }

    // Finish constructing configuration with the same flow as when not using
    // extensions.
    ImageCaptureConfig config = builder.build();
    ImageCapture useCase = new ImageCapture(config);
    CameraX.bindToLifecycle((LifecycleOwner)this, useCase);
}
于 2019-06-26T21:09:57.083 回答