问题
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