生成二维码到指定位置。
/**
*
*author:陌小伊
*/
public class moxiaoyi {
private static void generateQRCodeImage(String text, int width, int height, String filePath) throws WriterException, IOException, IOException {
QRCodeWriter qrCodeWriter = new QRCodeWriter();
HashMap<EncodeHintType, Object> hints = new HashMap<>();
hints.put(EncodeHintType.CHARACTER_SET, “utf-8”);
BitMatrix bitMatrix = qrCodeWriter.encode(text, BarcodeFormat.QR_CODE, width, height, hints);
Path path = FileSystems.getDefault().getPath(filePath);
MatrixToImageWriter.writeToPath(bitMatrix, “PNG”, path);
}
public static void main(String[] args) throws IOException, WriterException {
generateQRCodeImage(“Surprise or surprise”, 350, 350, “E:\”);
}
}