英文:
Scan a QR code and decode it using p:photoCam
问题
我需要在摄像头捕获图像的同时捕获和读取QR码,在一个JSF应用程序中完成这个任务。
我已经成功地从照片中读取了QR码,但现在我需要使它在摄像头捕获的图像中"活跃"起来。
有人有什么建议吗?
我正在尝试使用PrimeFaces的p:photoCam组件。
以下是使用Zxing来读取QR码的方法:
/**
*
* @param filePath
* @param charset
* @param hintMap
*
* @return QR码的值
*
* @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();
}
请注意,这是一个用于读取QR码的Java方法。
英文:
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
得分: 3
PrimeFaces Extensions 10将拥有一个pe:codeScanner
组件,用于从设备摄像头扫描条形码和QR码。
<!-- language: xhtml -->
<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
<!-- language: java -->
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
英文:
PrimeFaces Extensions 10 will have a pe:codeScanner
component to scan bar and QR codes from a device camera.
<!-- language: xhtml -->
<pe:codeScanner width="600"
height="400">
<p:ajax event="codeScanned"
listener="#{codeScannerController.onCodeScanned}"/>
</pe:codeScanner>
<!-- language: java -->
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));
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论