2013-07-30 244 views

回答

-1

使用ZXing API,您可以自己實現它。關於如何使用Android相機,請參閱Android website。下面是從預覽回調捕獲圖像,以及如何使用斑馬線的圖像解碼代碼:

private Camera.PreviewCallback mPreviewCallback = new PreviewCallback() { 

     @Override 
     public void onPreviewFrame(byte[] data, Camera camera) { 
      // TODO Auto-generated method stub 

      if (mDialog.isShowing()) 
       return; 

      LuminanceSource source = new PlanarYUVLuminanceSource(data, mWidth, mHeight, mLeft, mTop, mAreaWidth, mAreaHeight, false); 
      BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(
       source)); 
      Result result; 

      try { 
       result = mMultiFormatReader.decode(bitmap, null); 
       if (result != null) { 
        mDialog.setTitle("Result"); 
        mDialog.setMessage(result.getText()); 
        mDialog.show(); 
       } 
      } catch (NotFoundException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 
    }; 

有關詳細信息,您可以閱讀文章How to implement a simple barcode scan application on Android