我一直在尝试使用zxing和primefaces扫描QR码
filename = getRandomImageName();
byte[] data = captureEvent.getData();
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext()
.getContext();
String filePathToImage = servletContext.getRealPath("") + filename + ".jpeg";
FileImageOutputStream imageOutput;
try {
imageOutput = new FileImageOutputStream(new File(filePathToImage));
imageOutput.write(data, 0, data.length);
imageOutput.close();
String filePath = filePathToImage;
String charset = "UTF-8"; // or "ISO-8859-1"
Map hintMap = new HashMap();
hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
String scannedDetails = readQRCode(filePath, charset, hintMap);
System.out.println("Data read from QR Code: " + scannedDetails);
RequestContext.getCurrentInstance().execute("PF('QRcodeDialog').hide();");
RequestContext.getCurrentInstance().update("baseTemplateForm:receiver");
} catch (IOException e) {
showMessage(Constants.SUCCESS_MESSAGE_ID, FacesMessage.SEVERITY_ERROR,
"QR code not scanned properly. Please scan again.", null);
throw new FacesException("Error in writing captured image.", e);
} catch (NotFoundException e) {
showMessage(Constants.MESSAGE_ID_FOR_QR, FacesMessage.SEVERITY_ERROR,
"QR code not scanned properly. Please scan again.", null);
} catch (CommandCenterException e) {
logger.error("Error in fetching receiver details");
}
我想要的是连续扫描图像并自行检测QR码,而不是单击按钮调用此功能。
答案 0 :(得分:0)
要进行连续扫描是不可能的,而不是您想要做的事情,请记住带宽和服务器负载。您可以做的是使用p:poll
每隔几秒钟拍摄一次照片。使用photoWidth
,photoHeight
和jpegQuality
来节省带宽。尽可能地减少它们。另外,不要立即开始投票,而是在点击按钮开始时,一旦收到QR码就立即停止投票。