Android 二维码扫描工具 QRCodeReaderView

jopen 9年前

QRCodeReaderView 是基于 ZXING 条形码扫描工具项目改进,为了在肖像模式和增强现实目的下进行更简单的 Android 二维码检测。此项目可以在相机的预览中显示是否有二维码。

用法:

  • Create an Activity which implements onQRCodeReadListener, and let implements required methods
  • Make sure Activity orientation is PORTRAIT and give Camera permision in the manifest.xml
  • Add a "QRCodeReaderView" in the layout editor like you actually do with a button for example
 <com.dlazaro66.qrcodereaderview.QRCodeReaderView          android:id="@+id/qrdecoderview"         android:layout_width="match_parent"         android:layout_height="match_parent" />
  • In your onCreate method, you can find the view as usual, using findViewById() function.
  • Set onQRCodeReadListener to the QRCodeReaderView.
  • Start & Stop camera preview in onPause() and onResume() overriden methods.
  • Use onQRCodeReadListener callbacks as you want.
  • You can place widgets or views over QRDecoderView
  public class DecoderActivity extends Activity implements OnQRCodeReadListener {        private TextView myTextView;      private QRCodeReaderView mydecoderview;        @Override      protected void onCreate(Bundle savedInstanceState) {          super.onCreate(savedInstanceState);          setContentView(R.layout.activity_decoder);            mydecoderview = (QRCodeReaderView) findViewById(R.id.qrdecoderview);          mydecoderview.setOnQRCodeReadListener(this);            myTextView = (TextView) findViewById(R.id.exampleTextView);      }          // Called when a QR is decoded      // "text" : the text encoded in QR      // "points" : points where QR control points are placed      @Override      public void onQRCodeRead(String text, PointF[] points) {          myTextView.setText(text);      }          // Called when your device have no camera      @Override      public void cameraNotFound() {        }        // Called when there's no QR codes in the camera preview image      @Override      public void QRCodeNotFoundOnCamImage() {        }        @Override      protected void onResume() {          super.onResume();          mydecoderview.getCameraManager().startPreview();      }        @Override      protected void onPause() {          super.onPause();          mydecoderview.getCameraManager().stopPreview();      }  }


Image

项目主页:http://www.open-open.com/lib/view/home/1446534728935