簡體   English   中英

如何使用primefaces photocam功能檢測QR碼,拍攝快照並在java中對其進行解碼

[英]How to detect a QR code, take a snapshot and decode it in java using primefaces photocam feature

我一直在嘗試使用 zxing 和 primefaces 掃描二維碼

    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 碼,而不是通過單擊按鈕調用此函數。

p:photoCam

連續掃描是不可能的,也不是您想做的事情,請牢記帶寬和服務器負載。 您可以做的是使用p:poll每隔幾秒鍾拍攝一次照片。 使用photoWidthphotoHeightjpegQuality來節省帶寬。 盡可能減少它們。 此外,不要立即開始投票,而是在開始單擊按鈕時開始投票,並在收到二維碼后立即停止投票。

pe:codeScanner

從 PrimeFaces Extension 10 開始,您可以使用pe:codeScanner掃描二維碼。 它是“實時的”,您可以注冊一個 Ajax 偵聽器以將掃描的代碼發送到 bean。

看:

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM