2017-08-24 89 views
-2

我想要在掃描時捕獲矩形括號內的QR碼圖像。我知道QR碼圖像可以很容易地生成和顯示,但我的要求是顯示掃描的QR碼完全相同的圖像。如何在Android中掃描QR碼時同時捕捉圖像?

我曾嘗試下面的代碼:

scan_btn.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 
       IntentIntegrator integrator = new IntentIntegrator(activity); 
       integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE_TYPES); 
       integrator.setPrompt("Scan"); 
       integrator.setCameraId(0); 
       integrator.setBeepEnabled(false); 
       integrator.setBarcodeImageEnabled(false); 
       integrator.initiateScan(); 
      } 
     }); 

..... 

@Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); 
     if (result != null){ 
      Bitmap btm = (Bitmap) data.getExtras().get("data"); 

      ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
      btm.compress(Bitmap.CompressFormat.PNG, 100, stream); 
      image.setImageBitmap(btm); 
      if(result.getContents() == null){ 

       android.widget.Toast.makeText(this, "You cancelled the scanning", Toast.LENGTH_LONG).show(); 
      } 
      else { 
       android.widget.Toast.makeText(this, result.getContents(), Toast.LENGTH_LONG).show(); 
      } 

     } 
     else { 
      super.onActivityResult(requestCode, resultCode, data); 
     } 
    } 

但我得到空位圖。

+0

請告訴我們你已經嘗試了代碼,爲什麼它不工作 –

+0

喜基思男,我已經添加了我嘗試的代碼。 – Deepak

+1

看起來像你需要設置「setBarcodeImageEnabled」爲true。見https://github.com/journeyapps/zxing-android-embedded/issues/143 –

回答

0

首先,您需要將「setBarcodeImageEnabled」設置爲true,以便Barcode掃描儀捕獲靜脈曲張圖像。然後,當獲得條碼結果時,您可以獲取圖像。

@override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); 
    result.getBitmap() 
    result.getBitmapWithResultPoints(Color.YELLOW) 
} 

來源:https://github.com/journeyapps/zxing-android-embedded/issues/143