Java中生成二维码的方法
来源:互联网 发布:孙鑫windows编程视频 编辑:程序博客网 时间:2024/06/03 18:31
1.zxing
1).生成二维码
需要引入zxing core,zxing javase extensions 两个jar包
//设置图片宽度,高度,格式,内容 int width=300; int height=300; String format="png"; String content="老哥稳"; content=new String(content.getBytes("utf-8"),"iso-8859-1"); 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 encode = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height); //写入文件 Path file=new File("D:\\嘻嘻.png").toPath(); MatrixToImageWriter.writeToPath(encode, format, file); } catch (WriterException e) { // TODO Auto-generated catch block e.printStackTrace(); }
2).解析二维码
BufferedImage bi=ImageIO.read(new File("D://嘻嘻.png")); LuminanceSource ls=new BufferedImageLuminanceSource(bi); BinaryBitmap bb=new BinaryBitmap(new HybridBinarizer(ls) ); HashMap hints=new HashMap(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); MultiFormatReader mfw=new MultiFormatReader(); Result result = mfw.decode(bb,hints); System.out.println("二维码读取结果:"+result.toString());
2.jquery.qrcode 生成二维码
感觉这个还是比较方便的,后台传入前台一个字符串或者URL 然后生成一个二维码。方法呢很简单。引入jquery文件一样 引入 jquery.qrcode.min.js ,然后写入如下代码,就生成一个百度的二维码吧。
<div id="code"></div><script type="text/javascript" src="${basePath }/resource/js/jquery.min.js"></script><script type="text/javascript" src="${basePath }/resource/js/jquery.qrcode.min.js"></script><script type="text/javascript">$(function(){ $("#code").qrcode("https://www.baidu.com");});
阅读全文
1 0
- Java中生成二维码的方法
- java 生成 二维码的方法
- Java生成二维码方法
- java实现二维码生成的几个方法
- java实现二维码生成的几个方法
- java实现二维码生成的几个方法
- java实现二维码生成的几个方法
- Java实现二维码生成的几个方法
- java实现二维码生成的几个方法
- java实现二维码生成的几个方法
- java实现二维码生成的几个方法
- java实现二维码生成的几个方法
- java实现二维码生成的几个方法
- java生成二维码的几个方法
- java实现二维码生成的几个方法
- java实现二维码生成的几个方法
- java生成二维码方法事例
- 【java生成二维码方法事例】
- 【Linux】shell 语法
- JavaScript数组方法总结
- 修改hosts文件访问google、youtube等网站
- Git
- 流程控制 if语句和switch语句详解
- Java中生成二维码的方法
- python readline或者readlines添加'\n'问题
- vector和set
- ERROR /usr/local/nginx/logs/ nginx.pid"
- [读书笔记] 《Python 机器学习》
- poi导入excel中的日期字段
- Spring源码分析4 — spring bean创建和初始化
- java的缓存实例的不可变类
- AngularJS自定义指令之可选参数replace