【问题标题】:How to enable Android CameraX Vendor extensions?如何启用 Android CameraX 供应商扩展?
【发布时间】:2019-08-13 18:26:33
【问题描述】:

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

我在Android Developer Docs 阅读了有关供应商扩展的文章。我尝试重用他们的方法,但示例中显示的类不包含在 CameraX alpha-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 repository 找到,但如果不导入完整的 AndroidX 项目就很难设置它。

【问题讨论】:

    标签: java android android-camerax


    【解决方案1】:

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

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

    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"
    

    【讨论】:

      【解决方案2】:

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

      这是来自 Android Developer DocsKotlin 示例:

      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 DocsJava示例:

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

      【讨论】:

      • 问题是没有androidx.camera.extensions这样的包
      【解决方案3】:

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

      参考这个帖子, https://stackoverflow.com/a/57177147/11861734

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-05-05
        • 2019-02-18
        • 1970-01-01
        • 2018-03-29
        • 1970-01-01
        • 1970-01-01
        • 2021-07-15
        • 1970-01-01
        相关资源
        最近更新 更多