android—我的java代码中有一个bindpreview方法,但该方法的一部分,即image.setanalyzer没有运行

igsr9ssn  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(442)

我正在开发一个二维码扫描仪使用谷歌的ml工具包,我有一个方法叫bindpreview。当我调用方法时,方法中的部分代码没有被执行。这里是方法
void bindpreview(@nonnull processcameraprovider cameraprovider){

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

    CameraSelector cameraSelector = new CameraSelector.Builder()
            .requireLensFacing(CameraSelector.LENS_FACING_BACK)
            .build();

    DisplayMetrics metrics = new DisplayMetrics();
    Size screenSize = new Size(metrics.widthPixels, metrics.heightPixels);
    getWindowManager().getDefaultDisplay().getMetrics(metrics);

    ImageAnalysis imageAnalysis =
            new ImageAnalysis.Builder()
                    .setTargetResolution(screenSize)
                    .setTargetRotation(preview.getTargetRotation())
                    //.setTargetResolution(new Size(1280, 720))
                    .setBackpressureStrategy(ImageAnalysis.STRATEGY_KEEP_ONLY_LATEST)
                    .build();
    Toast.makeText(this, "In bind preview", Toast.LENGTH_SHORT).show();

    imageAnalysis.setAnalyzer(executor, new ImageAnalysis.Analyzer() {
        @Override
        public void analyze(@NonNull ImageProxy imageProxy) {
            Toast.makeText(BarcodeScanningActivity.this, "Now in set analyzer", Toast.LENGTH_SHORT).show();
            //int rotationDegrees = imageProxy.getImageInfo().getRotationDegrees();
            //Log.v(TAG, ""+rotationDegrees);
            myImageProxy = imageProxy;
            @SuppressLint("UnsafeExperimentalUsageError")
            Image mediaImage = imageProxy.getImage();
            if (mediaImage != null) {
                image = InputImage.fromMediaImage(mediaImage, imageProxy.getImageInfo().getRotationDegrees());
                // Pass image to an ML Kit Vision API
                // ...
                processImage(image);
            }
        }
    });

第一个toast说“bind preview is showing”,但是第二个toast说“now in set analyzer is not showing”,请在此处输入图像描述

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题