2017-08-24 72 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