Scan a QR code and decode it using p:photoCam

半腔热情 提交于 2021-01-28 21:19:51

问题


I need to capture and read a QR Code while the camera is capturing, all of this in a JSF Application.

I have already read a QR Code in a photo, but for now I have to make it "alive".

Anyone has any suggestion?

I'm trying to use the p:photoCam of PrimeFaces.

This is the method, using Zxing to read the QR code:

 /**
   * 
   * @param filePath
   * @param charset
   * @param hintMap
   * 
   * @return Qr Code value 
   * 
   * @throws FileNotFoundException
   * @throws IOException
   * @throws NotFoundException
   */
  public static String readQRCode(String filePath, String charset, Map hintMap)
      throws FileNotFoundException, IOException, NotFoundException {
    BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(
        new BufferedImageLuminanceSource(
            ImageIO.read(new FileInputStream(filePath)))));
    Result qrCodeResult = new MultiFormatReader().decode(binaryBitmap);
    return qrCodeResult.getText();
  }
}

回答1:


PrimeFaces Extensions 10 will have a pe:codeScanner component to scan bar and QR codes from a device camera.

<pe:codeScanner width="600"
                height="400">
  <p:ajax event="codeScanned"
          listener="#{codeScannerController.onCodeScanned}"/>
</pe:codeScanner>

Source: https://github.com/primefaces-extensions/primefaces-extensions/blob/master/showcase/src/main/webapp/sections/codeScanner/example-basicUsage.xhtml

public void onCodeScanned(final SelectEvent<Code> event) {
    final Code code = event.getObject();
    FacesContext.getCurrentInstance().addMessage(
                null,
                new FacesMessage(FacesMessage.SEVERITY_INFO,
                            String.format("Scanned: %s (%s)", code.getValue(), code.getFormat()),
                            null));
}

Source: https://github.com/primefaces-extensions/primefaces-extensions/blob/master/showcase/src/main/java/org/primefaces/extensions/showcase/controller/codescanner/CodeScannerController.java



来源:https://stackoverflow.com/questions/63174091/scan-a-qr-code-and-decode-it-using-pphotocam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!