本文介绍了扫描QR码并使用p:photoCam对其进行解码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在摄像头捕获时捕获并读取QR码,所有这些都在JSF应用程序中完成.

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

我已经阅读了照片中的QR码,但现在我必须将其设置为有效".

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

有人有什么建议吗?

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

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

这是使用Zxing读取QR码的方法:

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

推荐答案

PrimeFaces Extensions 10将具有一个 pe:codeScanner 组件,用于扫描设备摄像头中的条形码和QR码.

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>

来源: 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

这篇关于扫描QR码并使用p:photoCam对其进行解码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 07:15