1.jar 包 maven:
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.0.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.0.0</version>
</dependency>
2.代码
int width=300;
int height=300;
String format="png";
String content="傻逼";
//定义二维码参数
HashMap code = new HashMap();
code.put(EncodeHintType.CHARACTER_SET, "utf-8");
code.put(EncodeHintType.MARGIN, 2);
try{
BitMatrix encode = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,code);
Path file = new File("D:/test/img.png").toPath();
MatrixToImageWriter.writeToPath(encode,format,file);
}catch(Exception e){
e.printStackTrace();
}
本文介绍如何利用Zxing库的Java实现来生成指定内容的QR二维码图片。通过Maven引入必要的依赖,并提供了完整的示例代码,展示了设置二维码尺寸、格式及编码方式等关键步骤。
1584

被折叠的 条评论
为什么被折叠?



