无法从包 androidx.camera.core 导入 PreviewConfig 类



我正在尝试将camerax api用于相机应用程序,但是我遇到了一个问题。 类 PreviewConfig 无法解析。 这是我的build.gradle(app(文件

apply plugin: 'com.android.application'
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.cameraapi"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility = 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// CameraX core library
def camerax_version = "1.0.0-alpha09"
implementation "androidx.camera:camera-core:${camerax_version}"
implementation "androidx.camera:camera-camera2:${camerax_version}"
// If you want to use the CameraX View class
implementation "androidx.camera:camera-view:1.0.0-alpha06"
// If you want to use the CameraX Extensions library
implementation "androidx.camera:camera-extensions:1.0.0-alpha06"
// If you want to use the CameraX Lifecycle library
implementation "androidx.camera:camera-lifecycle:1.0.0-alpha03"
}

主活动.class文件是

package com.example.cameraapi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.PreviewConfig; //this line is showing error
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

在上面的代码行中,"import androidx.camera.core.PreviewConfig;"无法解析。

对于最近的camerax版本(我认为从alpha06或alpha07开始(,不再需要PreviewConfig来构建预览用例(这也适用于其他用例,ImageAnalysis和ImageCapture(。现在,您可以使用其生成器类生成预览实例。

Preview preview = new Preview.Builder().build();

当然,您可以使用构建器的方法根据需要对其进行配置(例如,设置目标分辨率(。

// Create configuration object for the viewfinder use case
val previewConfig = PreviewConfig.Builder().apply {
setTargetResolution(Size(640, 480))
}.build()

// Build the viewfinder use case
val preview = Preview(previewConfig)

// Build the viewfinder use case
val preview = Preview.Builder()
.setTargetResolution(Size(640, 480))
.build()

不幸的是,他们弃用了它,您应该查看更改。据我所知,而不是import androidx.camera.core.PreviewConfig;你应该使用import androidx.camera.core.impl.PreviewConfig

最新更新