简体   繁体   English

对“方法”的引用不明确

[英]Reference to "method" is ambiguous

When calling Builder() I am given the error message:调用 Builder() 时,我收到错误消息:

Reference to 'Builder' is ambiguous, both 'androidx.camera.core.impl.UseCaseConfig.Builder' and 'androidx.camera.core.impl.ImageOutputConfig.Builder' match对“Builder”的引用不明确,“androidx.camera.core.impl.UseCaseConfig.Builder”和“androidx.camera.core.impl.ImageOutputConfig.Builder”都匹配

The error is produced within the startCamera() function.该错误是在 startCamera() 函数中产生的。 How would I make sure the compiler knows to use the UseCaseConfig option?我如何确保编译器知道使用 UseCaseConfig 选项? Any help is appreciated, thank you for your time and help.任何帮助表示赞赏,感谢您的时间和帮助。

package com.example.atlas2.Activities.Login.UserCreation.ProfilePhotoCamerax;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.camera.core.impl.PreviewConfig;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;

import android.content.pm.PackageManager;
import android.graphics.Matrix;
import android.os.Bundle;
import android.util.Rational;
import android.util.Size;
import android.view.Surface;
import android.view.TextureView;
import android.widget.Toast;

import com.example.atlas2.R;

public class ProfilePhotoActivityX extends AppCompatActivity {


    private int REQUEST_CODE_PERMISSIONS = 101;
    private final String[] REQUIRED_PERMISSIONS = new String[]{"android.permission.CAMERA", 
                                                  "android.permission.WRITE_EXTERNAL_STORAGE"};
    TextureView textureView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_profile_photo_x);

        textureView = findViewById(R.id.view_finder);

        if(allPermissionsGranted()){
            startCamera(); //start camera if permission has been granted by user
        } else{
            ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS);
        }
    }

    private void startCamera() {

        Rational aspectRatio = new Rational(textureView.getWidth(), textureView.getHeight());
        Size screen = new Size(textureView.getWidth(), textureView.getHeight());

        PreviewConfig pConfig = new PreviewConfig.Builder<>();

    }

    private void updateTransform(){
        Matrix mx = new Matrix();
        float w = textureView.getMeasuredWidth();
        float h = textureView.getMeasuredHeight();

        float cX = w / 2f;
        float cY = h / 2f;

        int rotationDgr;
        int rotation = (int)textureView.getRotation();

        switch(rotation){
            case Surface.ROTATION_0:
                rotationDgr = 0;
                break;
            case Surface.ROTATION_90:
                rotationDgr = 90;
                break;
            case Surface.ROTATION_180:
                rotationDgr = 180;
                break;
            case Surface.ROTATION_270:
                rotationDgr = 270;
                break;
            default:
                return;
        }

        mx.postRotate((float)rotationDgr, cX, cY);
        textureView.setTransform(mx);
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull 
                                           int[] grantResults) {

        if(requestCode == REQUEST_CODE_PERMISSIONS){
            if(allPermissionsGranted()){
                startCamera();
            } else{
                Toast.makeText(this, "Permissions not granted by the user.", 
                               Toast.LENGTH_SHORT).show();
                finish();
            }
        }
    }

    private boolean allPermissionsGranted(){

        for(String permission : REQUIRED_PERMISSIONS){
            if(ContextCompat.checkSelfPermission(this, permission) != 
               PackageManager.PERMISSION_GRANTED){
                return false;
            }
        }
        return true;
    }
}

First of all - what version of CameraX are you using?首先 - 您使用的是什么版本的CameraX The latest(at the time of writing) is alpha09(core) in which you should build your preview like this:最新的(在撰写本文时)是 alpha09(core),您应该像这样构建预览:

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

You can then easily use whichever set methods in builder for your preview configuration.然后,您可以轻松地使用构建器中的任何设置方法进行预览配置。 The google docs are not completely updated to newest version yet so you can use the forum for help.谷歌文档尚未完全更新到最新版本,因此您可以使用论坛寻求帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM