首页 > 其他 > 详细

生成二维码

时间:2020-05-18 15:33:44      阅读:61      评论:0      收藏:0      [点我收藏+]

引入maven依赖

<!-- google二维码生成包 -->
<dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>javase</artifactId>
    <version>3.3.0</version>
</dependency>

<dependency>
    <groupId>com.google.zxing</groupId>
    <artifactId>core</artifactId>
    <version>2.0</version>
</dependency>

 

String code_url="java程序猴";//定义转成二维码的内容
if(code_url==null){
throw new NullPointerException();
}

//生成二维码配置
Map<EncodeHintType,Object> hints=new HashMap<>();
//设置纠错等级
hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);
//编码类型
hints.put(EncodeHintType.CHARACTER_SET,"UTF-8");
//bitMatrix对象生成二维码
BitMatrix bitMatrix=new MultiFormatWriter().encode(code_url, BarcodeFormat.QR_CODE,400,400,hints);
OutputStream out=response.getOutputStream();

MatrixToImageWriter.writeToStream(bitMatrix,"png",out);

此种方式是我常用的生成二维码方式  感觉很好用  各位大神请笑纳!

推荐二维码学习地址:

https://coolshell.cn/articles/10590.html

生成二维码

原文:https://www.cnblogs.com/java-cxh/p/12910697.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!