Zxing扫描仪相机变焦

时间:2018-09-28 13:37:59

标签: java android camera zoom zxing

我已经尝试解决问题3天了,但是我仍然没有找到答案。 我想在通过Zxing扫描仪扫描qrcode的同时向相机添加ZOOM。

build.gradle:

   implementation 'me.dm7.barcodescanner:zxing:1.9.8'

Xml:

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

</FrameLayout>

ScannerFragment:

    @Override
       public void onResume() {
         super.onResume();
         activateScanner();
     }

   private ViewGroup contentFrame;
   private ZXingScannerView zXingScannerView;

    private void activateScanner() {
    if(zXingScannerView != null) {

        if(zXingScannerView.getParent()!=null) {
            ((ViewGroup) 
     zXingScannerView.getParent()).removeView(zXingScannerView); // to 
      prevent crush on re adding view
        }
        contentFrame.addView(zXingScannerView);

        if(zXingScannerView.isActivated()) {
            zXingScannerView.stopCamera();
        }

        zXingScannerView.startCamera(camId);
        zXingScannerView.setFlash(isFlash);
        //zXingScannerView.setAutoFocus(isAutoFocus);
    }
}

我添加了SeekBar,并希望通过它控制摄像机的缩放。

private Camera cameraZoom;
@Override
public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

   try { 
       Camera.Parameters parameters = cameraZoom.getParameters(); 
   } 
   catch (NullPointerException e) { 
       Log.d("NullP",e.getMessage()); 
   }
}

日志:

D/NullP: Attempt to invoke virtual method 'android.hardware.Camera$Parameters android.hardware.Camera.getParameters()' on a null object reference

我尝试使用上面的代码执行此操作,但是只有错误

请告诉我该怎么做。

2 个答案:

答案 0 :(得分:0)

int count = 0;    
using (new SqlConnection connection = new SqlConnection("connectionString"))
{
    sqlCommand cmd = new SqlCommand("SELECT COUNT(*) FROM table_name", connection);
    connection.Open();
    count = (int32)cmd.ExecuteScalar();
}

您的代码中缺少此行。

答案 1 :(得分:0)

当Zxing打开相机时,您无法打开相机,因此cameraZoom.getParameters()(cameraZoom为空)。