项目作者: Dynamsoft

项目描述 :
高级语言: Java
项目地址: git://github.com/Dynamsoft/android-barcode-decode-video.git
创建时间: 2019-07-15T06:35:16Z
项目社区:https://github.com/Dynamsoft/android-barcode-decode-video

开源协议:

下载


Real-time barcode scanning from Android camera stream

How to build a simple Android barcode scanning app with Android camera API and Dynamsoft Barcode Reader.

Learn more about Dynamsoft Barcode Reader SDK >

What You Should Know

Resources

Barcode scanning from Android camera stream

Call startDecodingFrame() to initialize the environment and call appendFrame() repeatedly to add the preview images.

  1. cameraView.addFrameProcessor(new FrameProcessor() {
  2. @SuppressLint("NewApi")
  3. @Override
  4. public void process(@NonNull final Frame frame) {
  5. try {
  6. if (isDetected && isCameraOpen) {
  7. YuvImage yuvImage = new YuvImage(frame.getData(), ImageFormat.NV21,
  8. frame.getSize().getWidth(), frame.getSize().getHeight(), null);
  9. if (width == 0) {
  10. width = yuvImage.getWidth();
  11. height = yuvImage.getHeight();
  12. stride = yuvImage.getStrides()[0];
  13. reader.setErrorCallback(errorCallback, null);
  14. reader.setTextResultCallback(textResultCallback, null);
  15. reader.setIntermediateResultCallback(intermediateResultCallback, null);
  16. // start a new thread to decode barcodes
  17. reader.startFrameDecoding(10, 10, width, height, stride, EnumImagePixelFormat.IPF_NV21, "");
  18. } else {
  19. PublicRuntimeSettings s = reader.getRuntimeSettings();
  20. // add new image frames for barcode scanning
  21. int frameid = reader.appendFrame(yuvImage.getYuvData());
  22. Log.i("FrameId", frameid + "");
  23. }
  24. if (bUpateDrawBox) {
  25. bUpateDrawBox = false;
  26. Message message = handler.obtainMessage();
  27. Rect imageRect = new Rect(0, 0, width, height);
  28. message.obj = imageRect;
  29. message.what = 0x001;
  30. handler.sendMessage(message);
  31. }
  32. isDetected = true;
  33. }
  34. } catch (Exception e) {
  35. e.printStackTrace();
  36. }
  37. }
  38. });