Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 参考「;方法“;含糊不清_Java_Android_Android Camera_Android Camerax - Fatal编程技术网

Java 参考「;方法“;含糊不清

Java 参考「;方法“;含糊不清,java,android,android-camera,android-camerax,Java,Android,Android Camera,Android Camerax,调用Builder()时,我收到错误消息: “Builder”的引用不明确,“androidx.camera.core.impl.UseCaseConfig.Builder”和“androidx.camera.core.impl.ImageOutputConfig.Builder”都匹配 该错误是在startCamera()函数中产生的。 如何确保编译器知道使用UseCaseConfig选项? 感谢您的帮助,谢谢您的时间和帮助 package com.example.atlas2.Activit

调用Builder()时,我收到错误消息:

“Builder”的引用不明确,“androidx.camera.core.impl.UseCaseConfig.Builder”和“androidx.camera.core.impl.ImageOutputConfig.Builder”都匹配

该错误是在startCamera()函数中产生的。 如何确保编译器知道使用UseCaseConfig选项? 感谢您的帮助,谢谢您的时间和帮助

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;
    }
}
package com.example.atlas2.Activities.Login.UserCreation.ProfilePhotoCamerax;
导入androidx.annotation.NonNull;
导入androidx.appcompat.app.appcompat活动;
导入androidx.camera.core.impl.PreviewConfig;
导入androidx.core.app.ActivityCompat;
导入androidx.core.content.ContextCompat;
导入android.content.pm.PackageManager;
导入android.graphics.Matrix;
导入android.os.Bundle;
导入android.util.Rational;
导入android.util.Size;
导入android.view.Surface;
导入android.view.TextureView;
导入android.widget.Toast;
导入com.example.atlas2.R;
公共类ProfilePhotoActivityX扩展了AppCompatActivity{
私有int请求\代码\权限=101;
private final String[]REQUIRED_PERMISSIONS=新字符串[]{“android.permission.CAMERA”,
“android.permission.WRITE\u EXTERNAL\u STORAGE”};
纹理视图纹理视图;
@凌驾
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity\u profile\u photo\x);
textureView=findViewById(R.id.view\U finder);
如果(allPermissionsGranted()){
startCamera();//如果用户已授予权限,则启动摄像头
}否则{
ActivityCompat.requestPermissions(这是必需的权限,请求代码权限);
}
}
私有void startCamera(){
RationalAspectRatio=新的Rational(textureView.getWidth(),textureView.getHeight());
大小屏幕=新大小(textureView.getWidth(),textureView.getHeight());
PreviewConfig pConfig=新建PreviewConfig.Builder();
}
私有void updateTransform(){
矩阵mx=新矩阵();
float w=textureView.getMeasuredWidth();
float h=textureView.getMeasuredHeight();
浮子cX=w/2f;
浮球cY=h/2f;
int-rotationDgr;
int rotation=(int)textureView.getRotation();
开关(旋转){
外壳表面旋转0:
旋转dgr=0;
打破
外壳表面旋转90度:
旋转dgr=90;
打破
外壳表面旋转180度:
旋转dgr=180;
打破
外壳表面。旋转_270:
旋转dgr=270;
打破
违约:
返回;
}
mx.postRotate((浮动)旋转dgr、cX、cY);
textureView.setTransform(mx);
}
@凌驾
public void onRequestPermissionsResult(int-requestCode,@NonNull字符串[]权限,@NonNull
int[]格兰特结果){
if(requestCode==请求\代码\权限){
如果(allPermissionsGranted()){
startCamera();
}否则{
Toast.makeText(这是“用户未授予的权限”,
吐司。长度(短)。show();
完成();
}
}
}
私有布尔值allPermissionsGranted(){
for(字符串权限:必需的\u权限){
if(ContextCompat.checkSelfPermission(this,permission)!=
PackageManager.权限(已授予){
返回false;
}
}
返回true;
}
}

首先-您使用的是什么版本的?最新版本(在撰写本文时)是alpha09(core),在该版本中,您应该按照以下方式构建预览:

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

然后,您可以轻松地使用builder中的任何一种方法进行预览配置。尚未完全更新到最新版本,因此您可以使用获取帮助。

尝试重命名方法名称,可能与源代码不明确。@Alex Michael您是否找到解决此问题的方法?