<!-- https://mvnrepository.com/artifact/com.google.zxing/core  生成二维码 -->
<dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>core</artifactId>
    <version>3.3.0</version>
</dependency>
<dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>javase</artifactId>
    <version>3.3.0</version>
</dependency>

 

操作代码

JSONObject jsonObject = new JSONObject();
jsonObject.put("userName","alex");
String s = jsonObject.toJSONString();
System.out.println(s);

// 定义图片宽度
int width = 200;
// 定义图片高度
int height= 200;

Map<EncodeHintType,Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET,"UTF-8");
BitMatrix bitMatrix = new MultiFormatWriter().encode(s, BarcodeFormat.QR_CODE,width,height,hints);

String filePath = "D://";
String fileName = "qrCode.jpg";

// 定义路径对象
Path path = FileSystems.getDefault().getPath(filePath,fileName);
MatrixToImageWriter.writeToPath(bitMatrix,"jpg",path);

System.out.println(path);

 

相关文章:

  • 2021-06-08
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
  • 2021-04-22
  • 2022-12-23
  • 2022-01-20
  • 2022-02-07
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2022-01-10
  • 2021-11-27
  • 2021-07-27
  • 2021-11-26
  • 2022-12-23
相关资源
相似解决方案