public static void main(String[] args) {
int width = 200;
int height = 200;
//保存的格式
String format = "png";
//扫到的内容
String content = "晓琦,我爱你!";
//定义二维码参数
HashMap hints = new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
//纠错率
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
//边距
hints.put(EncodeHintType.MARGIN, 1);
try {
BitMatrix encode = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,hints);
Path string = new File("d:/image.png").toPath();
MatrixToImageWriter.writeToPath(encode, format,string);
} catch (Exception e) {
e.printStackTrace();
}
}
资源文件,请见上传的资源
用zxing.jar来生成二维码
最新推荐文章于 2023-05-31 12:59:27 发布
