Demo entry 6789097

生成二维码

   

Submitted by anonymous on Apr 25, 2019 at 13:24
Language: Java. Code size: 611 Bytes.

   public static void getQRCode(String contents, OutputStream stream) throws WriterException, IOException {
        QRCodeWriter qrCode = new QRCodeWriter();
        Map hints = new HashMap<>();
        //设置编码方式和容错率
        hints.put(EncodeHintType.CHARACTER_SET, CHARACTER_SET);
        hints.put(EncodeHintType.ERROR_CORRECTION, ERROR_CORRECTION);
        BitMatrix qrcode = qrCode.encode(contents, BarcodeFormat.QR_CODE, DEF_WIDTH, DEF_HEIGHT, hints);
        //new MatrixToImageConfig() 颜色配置,默认为黑白二色
        MatrixToImageWriter.writeToStream(qrcode, "png", stream, new MatrixToImageConfig());
    }

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).