【问题标题】:Scan a QR code and decode it using p:photoCam扫描二维码并使用 p:photoCam 对其进行解码
【发布时间】:2020-07-30 13:19:22
【问题描述】:

我需要在相机捕捉时捕捉和读取二维码,所有这些都在 JSF 应用程序中。

我已经阅读了照片中的二维码,但现在我必须让它“活着”。

有人有什么建议吗?

我正在尝试使用 PrimeFaces 的 p:photoCam。

这是方法,使用Zxing读取二维码:

 /**
   * 
   * @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();
  }
}

【问题讨论】:

  • 我在这里没有看到任何与 JSF 或 PrimeFaces 相关的代码/尝试
  • 使用 PrimeFaces 组件尚无法实现。见github.com/primefaces-extensions/…
  • 我明白了!!!现在我的问题是用 chrome 或 firefox 打开相机,使用 primefaces 6.1.RC2,但我知道这个版本的 p:photoCam 并不完美。如何仅更新此组件并保留我的 Primefaces 版本?
  • 您为什么要继续使用候选版本?我建议在 PrimeFaces 9 发布的那一刻升级到它。举个例子,jQuery 中有一个 XSS 漏洞,在 9 中修复。forum.primefaces.org/viewtopic.php?f=3&t=63144

标签: java jsf primefaces camera qr-code


【解决方案1】:

PrimeFaces Extensions 10 将包含一个 pe:codeScanner 组件,用于从设备摄像头扫描条码和二维码。

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

来源: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));
}

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-09
    • 1970-01-01
    • 2022-07-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多