| | |
| | | */ |
| | | public static byte[] getQRCodeImage(String text, int width, int height) throws WriterException, IOException { |
| | | QRCodeWriter qrCodeWriter = new QRCodeWriter(); |
| | | BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height); |
| | | |
| | | HashMap<EncodeHintType, Object> hints = new HashMap<>(); |
| | | hints.put(EncodeHintType.CHARACTER_SET, "utf-8"); |
| | | |
| | | BitMatrix bitMatrix =qrCodeWriter.encode(text,BarcodeFormat.QR_CODE, width, height,hints); |
| | | //BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height); |
| | | |
| | | ByteArrayOutputStream pngOutputStream = new ByteArrayOutputStream(); |
| | | MatrixToImageWriter.writeToStream(bitMatrix, "JPG", pngOutputStream); |
| | | byte[] pngData = pngOutputStream.toByteArray(); |
| | | return pngData; |
| | | //返回 |
| | | return pngOutputStream.toByteArray(); |
| | | } |
| | | |
| | | } |