二维码

import com.google.zxing.*;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.client.j2se.MatrixToImageConfig;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.common.HybridBinarizer;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;public class QRCodeTest {public static void main(String[] args) {try {String s = "202101051020295,http://www.abc.com";String[] datas = s.split(",");for (String data: datas ) {QREncode(data,"D:\\新建文件夹\\",data,"gif");QRReader(new File("D:\\新建文件夹\\"+data+".gif"));}} catch (IOException e) {e.printStackTrace();} catch (NotFoundException e) {e.printStackTrace();}}/*** 生成二维码* @param content 二维码内容* @param path 生成的路径* @param filename 生成的图像文件名* @param format 生成的图像文件格式* @throws WriterException* @throws IOException*/public static void QREncode(String content,String path,String filename,String format) throws WriterException, IOException {//        String content = "个人博客:https://www.cnblogs.com/huanzi-qch/";//二维码内容int width = 300; // 图像宽度int height = 300; // 图像高度
//        String                      format = "gif";// 图像类型Map<EncodeHintType, Object> hints  = new HashMap<>();//内容编码格式hints.put(EncodeHintType.CHARACTER_SET, "UTF-8");// 指定纠错等级hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H);//设置二维码边的空度,非负数hints.put(EncodeHintType.MARGIN, 1);BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);String fullFileName = path.concat(filename).concat(".").concat(format);MatrixToImageWriter.writeToPath(bitMatrix, format, new File(fullFileName).toPath());// 输出原图片MatrixToImageConfig matrixToImageConfig = new MatrixToImageConfig(0xFF000001, 0xFFFFFFFF);/*问题:生成二维码正常,生成带logo的二维码logo变成黑白原因:MatrixToImageConfig默认黑白,需要设置BLACK、WHITE解决:https://ququjioulai.iteye.com/blog/2254382*/BufferedImage bufferedImage = LogoMatrix(MatrixToImageWriter.toBufferedImage(bitMatrix,matrixToImageConfig), new File("D:\\logo.png"));// BufferedImage bufferedImage = LogoMatrix(toBufferedImage(bitMatrix), new File("D:\\logo.png"));String fullFileName1 = path.concat(filename).concat("1").concat(".").concat(format);ImageIO.write(bufferedImage, format, new File(fullFileName1));//输出带logo图片System.out.println("输出成功.");}/*** 识别二维码*/public static void QRReader(File file) throws IOException, NotFoundException {MultiFormatReader formatReader = new MultiFormatReader();//读取指定的二维码文件BufferedImage bufferedImage =ImageIO.read(file);BinaryBitmap binaryBitmap= new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(bufferedImage)));//定义二维码参数Map  hints= new HashMap<>();hints.put(EncodeHintType.CHARACTER_SET, "utf-8");com.google.zxing.Result result = formatReader.decode(binaryBitmap, hints);//输出相关的二维码信息System.out.println("解析结果:"+result.toString());System.out.println("二维码格式类型:"+result.getBarcodeFormat());System.out.println("二维码文本内容:"+result.getText());bufferedImage.flush();}/*** 二维码添加logo* @param matrixImage 源二维码图片* @param logoFile logo图片* @return 返回带有logo的二维码图片* 参考:https://blog.csdn.net/weixin_39494923/article/details/79058799*/public static BufferedImage LogoMatrix(BufferedImage matrixImage, File logoFile) throws IOException {/*** 读取二维码图片,并构建绘图对象*/Graphics2D g2 = matrixImage.createGraphics();int matrixWidth = matrixImage.getWidth();int matrixHeigh = matrixImage.getHeight();/*** 读取Logo图片*/BufferedImage logo = ImageIO.read(logoFile);//开始绘制图片g2.drawImage(logo,matrixWidth/5*2,matrixHeigh/5*2, matrixWidth/5, matrixHeigh/5, null);//绘制BasicStroke stroke = new BasicStroke(5,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);g2.setStroke(stroke);// 设置笔画对象//指定弧度的圆角矩形RoundRectangle2D.Float round = new RoundRectangle2D.Float(matrixWidth/5*2, matrixHeigh/5*2, matrixWidth/5, matrixHeigh/5,20,20);g2.setColor(Color.white);g2.draw(round);// 绘制圆弧矩形//设置logo 有一道灰色边框BasicStroke stroke2 = new BasicStroke(1,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);g2.setStroke(stroke2);// 设置笔画对象RoundRectangle2D.Float round2 = new RoundRectangle2D.Float(matrixWidth/5*2+2, matrixHeigh/5*2+2, matrixWidth/5-4, matrixHeigh/5-4,20,20);g2.setColor(new Color(128,128,128));g2.draw(round2);// 绘制圆弧矩形g2.dispose();matrixImage.flush() ;return matrixImage ;}
}
<!--二维码--><dependency><groupId>com.google.zxing</groupId><artifactId>javase</artifactId><version>3.2.1</version></dependency><!-- ZXing --><dependency><groupId>com.google.zxing</groupId><artifactId>core</artifactId><version>3.3.3</version><!--3.2.1--></dependency>
BarPdf417AsBase64<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec --><dependency><groupId>commons-codec</groupId><artifactId>commons-codec</artifactId><version>1.14</version></dependency><dependency><groupId>com.lowagie</groupId><artifactId>iText</artifactId><version>2.1.5</version></dependency>

package com.doing.utils;import org.apache.commons.codec.binary.Base64;import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import java.nio.charset.StandardCharsets;public class BarcodePDF417Utils {/*** @Author Mr伍* @Description //TODO * @Date  2021/3/4* @Param [codeString]  字符串* @return java.lang.String  返回base64字符串**/public static String createPdf417AsBase64(String codeString){com.lowagie.text.pdf.BarcodePDF417 pdf = new com.lowagie.text.pdf.BarcodePDF417();pdf.setText(codeString.getBytes(StandardCharsets.UTF_8));Image pdfImg = pdf.createAwtImage(Color.black, Color.white);BufferedImage img = new BufferedImage((int)pdfImg.getWidth(null), (int)pdfImg.getHeight(null), BufferedImage.TYPE_INT_RGB);Graphics g = img.getGraphics();g.drawImage(pdfImg, 0, 0, Color.white, null);ByteArrayOutputStream bos = new ByteArrayOutputStream();
//        ImageIO.write(img, "PNG", bos);try {ImageIO.write(img, "BMP", bos);} catch (IOException e) {e.printStackTrace();}Base64 base64 = new Base64();String s = base64.encodeToString(bos.toByteArray());return s;}
}
二维码

PDF417码

前端HTML生成二维码带log(兼容所有游览器)

<!DOCTYPE html>
<html><head><meta charset="utf-8" /><title></title></head><body><script type="text/javascript" src="js/jquery-1.11.1.js" ></script><script type="text/javascript" src="js/jquery.qrcode.js" ></script><script type="text/javascript" src="js/qrcode.js" ></script> <script type="text/javascript" src="js/utf.js" ></script><p>Render in table</p><div id="qrcodeTable"></div><p>Render in canvas</p><div id="qrcodeCanvas"></div><script> jQuery('#qrcodeTable').qrcode({render    : "table",                <!--二维码生成方式 -->text    : "http://www.baidu.com" , <!-- 二维码内容  -->width : "200",               //二维码的宽度height : "200",});    jQuery('#qrcodeCanvas').qrcode({render    : "canvas",text    : "https://u.wechat.com/MInSjZ0QLtR0PTfqq3D5iO0",width : "200",               //二维码的宽度height : "200",              //二维码的高度background : "#ffffff",       //二维码的后景色foreground : "#000000",        //二维码的前景色src: 'img/1.jpg'             //二维码中间的图片});    </script></body>
</html>

jquery.qrcode.js

链接:https://pan.baidu.com/s/1rqDyDC1ttJjdun2_6ckWWw
提取码:j45u

jquery-1.11.1.js

链接: https://pan.baidu.com/s/1I2Xa7TTNDl6l5NRdVqwVNA 提取码: itbq 复制这段内容后打开百度网盘手机App,操作更方便哦

qrcode.js

链接:https://pan.baidu.com/s/1kgIgsTG1Duz0LGfWtb1Rcw
提取码:9c7u

utf.js

链接:https://pan.baidu.com/s/1rBxd8FnH0uF354OMFW0EtA
提取码:q8iv

QRCode二维码与PDF417码生成与读取JAVA+HTML相关推荐

  1. QRCode二维码生成方案及其在带LOGO型二维码中的应用(2)

    QRCode二维码生成方案及其在带LOGO型二维码中的应用(2) 原文:QRCode二维码生成方案及其在带LOGO型二维码中的应用(2) 续前:QRCode二维码生成方案及其在带LOGO型二维码中的应 ...

  2. qrcode二维码生成工具

    本篇,笔者介绍下自己用java开发的一款QR码生成器图形化工具. qrcode编码.解码功能依赖于google的二维码开源库google.zxing. 笔者项目github地址: https://gi ...

  3. QRCode二维码生成方案及其在带LOGO型二维码中的应用(1)

    提要:很多公司为商业宣传之需,常将企业LOGO加入二维码中,但如果LOGO遮挡区域足够地大,二维码就变得无法识别.那么,有没有一种办法将上述区域预先"抠空"出来(以便专门放置LOG ...

  4. C语言QRCode二维码生成

    随着二维码的应用越来越广泛,最近越来越多多朋友都在寻找用C语言生成QRCode二维码相关资料.C语言可以在很多种平台中移植,像51单片机,ARM等MCU中处理.网络上基于C语言的应用实例非常少,大部分 ...

  5. AutoCAD一维码、二维码的生成及使用,含Data Matrix,QRCode二维码、EAN-13条形码

    背景 一维条码即指条码条和空的排列规则,常用的一维码的码制包括:QRCode二维码.Data Matrix二维码.EAN码.39码.交叉25码.UPC码.128码.93码,ISBN码,及Codabar ...

  6. java创建QRCode二维码的三种方式

    自己在网上看视频学习了下如何使用java创建二维码,感觉还是挺有趣的,有小心思的还可以把秘密存入二维码中噢 视频源网址:http://www.imooc.com/learn/531 点击下载jar包 ...

  7. KING_C#学习之QRCode二维码(一)——基础知识扫盲

    在移动互联网快速发展下,二维码的应用非常广泛,且前景甚好.现在的登陆.分享等功能都可以利用二维码快速便捷地把信息传送出去,我个人是比较喜欢用这个技术,所以凭着兴趣以及二维码的强大,对二维码的相关知识做 ...

  8. C# QRCode 二维码

    /************************************************************************ C# QRCode 二维码* 说明:* 本文记录如何 ...

  9. 详解 Python qrcode 二维码模块

    原文链接 摘要: 详解 Python qrcode 二维码模块. 项目地址 https://github.com/lincolnloop/python-qrcode 声明 importqrcode 使 ...

  10. 隐藏在QRCode二维码背后的秘密

    隐藏在QRCode二维码背后的秘密,您知道吗? 1.容错级. 二维码的容错级分别为:L,M,Q和H.其中,L最低,H最高.如何从二维码中一眼看出其容错级别呢?看下图: 图1  容错级示例 如上图所示, ...

最新文章

  1. 6月Python热文Top10,精选自1000篇文章
  2. 绘制多边形_PS学习教程!教你绘制低多边形星空效果熊猫头像
  3. 天天说架构师,到底什么样的程序员能称为架构师?
  4. Linux常用命令行
  5. android 筛选控件_Flutter学习六之实现一个带筛选的列表页面
  6. _cdecl和_stdcal的区别
  7. RPC框架Dubbo分析
  8. 超声波测距仪编程_超声波测距仪参考(含原理图程序)
  9. Go语言基础环境配置(windows)
  10. python去除图片复杂背景_去掉图片黑背景输出为透明背景
  11. 打印机怎么无线扫描到计算机,富士施乐打印机CM215fw无线扫描到电脑功能的使使用教程...
  12. jeesit1.27(4)-数据权限控制
  13. Protel转PADS
  14. 用计算机配置打印机IP,如何修改打印机IP地址?
  15. Codeforces-697C Lorenzo Von Matterhorn
  16. 大学四年,我做过哪些兼职
  17. Apache POI读合并单元格
  18. 吉林大学计算机李昕,本报新聘百名特约教工通讯员
  19. 8-14-粘包问题、(通过简单报头)解决粘包问题、定制复杂报头
  20. 【区块链 | Polygon】Polygon区块链PHP开发包-使用PHP语言开发Polygon

热门文章

  1. windows常用端口对应表
  2. UWA学堂|逻辑代码模块
  3. 校验电话号码 手机号码正则表达式————转载
  4. 利用VBA操作OutLook批量发送工资条
  5. Unity 如何实现批量修改图片格式
  6. 使用EXCEL进行线性回归
  7. Java Web之EL表达式和JSTL
  8. c语言单片机题目设计大全,51单片机毕业设计题目.docx
  9. 方便检测电脑配置的软件收集
  10. 学院教务管理系统php,黄淮学院教务管理系统入口http://cms2.huanghuai.edu.cn/s.php/jwc/...