二维码zxing3.3.3.jar包
public static void main(String[] args) { //定义图片高度和宽度 int width = 300; int height =300; //定义图片格式 String format = "png"; //定义连接地址 String contents = "http://www.jd.com"; //定义二维码的参数 HashMap hints = new HashMap(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8");//设置字符集 hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);//设置纠错等级 hints.put(EncodeHintType.MARGIN, 2);//设置边距 //生成二维码 try { BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width , height); Path file = new File("D:/code/img.png").toPath(); MatrixToImageWriter.writeToPath(bitMatrix, format, file); } catch (Exception e) { e.printStackTrace(); } }
用户评论