public void generateQRCode(int width, int height, String content, OutputStream dest) throws IOException, WriterException { Map<EncodeHintType, Object> map = new HashMap<>(); map.put(EncodeHintType.CHARACTER_SET, "utf-8"); map.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M); map.put(EncodeHintType.MARGIN, 2); BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, map); MatrixToImageWriter.writeToStream(matrix, "png", dest); }
|