一维码是粗细不同、黑白相间的条、空及相应的字符组成的一维码信息;存储数字、字母
二维码是用某种特定的几何图形按一定的规律在平面分布的黑白相间条 空的图形 记录数据符号信息的图形
存储数字、字母、汉字、图片等
白色0,黑色代表二进制的1,分为线性堆叠式二维码建立在一维条码基础上按需要堆积成两行或者多行、
矩阵式二维码在矩阵空间用黑白像素在矩阵的不同分布进行编码、邮政码通过不同的条进行编码用于邮政编码;
优点:高密度编码,信息容量大可容纳500多汉字;编码范围广,容错能力强;译码可靠性高;可加入加密措施;成本低,易制作,持久耐用;
缺点:成为手机病毒、钓鱼网站传播的新渠道;信息泄露;
二维码是用某种特定的几何图形按一定的规律在平面分布的黑白相间条 空的图形 记录数据符号信息的图形
存储数字、字母、汉字、图片等
白色0,黑色代表二进制的1,分为线性堆叠式二维码建立在一维条码基础上按需要堆积成两行或者多行、
矩阵式二维码在矩阵空间用黑白像素在矩阵的不同分布进行编码、邮政码通过不同的条进行编码用于邮政编码;
优点:高密度编码,信息容量大可容纳500多汉字;编码范围广,容错能力强;译码可靠性高;可加入加密措施;成本低,易制作,持久耐用;
缺点:成为手机病毒、钓鱼网站传播的新渠道;信息泄露;
目前流行的三大国际标准:PDF417,不支持中文;DM专利未公开,需要付费;QR code 专利公开支持中文:具有识读速度快,数据密度大,占用空间小的优势;
jsp生成二维码方法:1借助第三方jar 如zxing和qrcodejar 2 javascript 如jquery.qrcode.js
QR Code是由日本Denso公司在94年研制的一种矩阵二维码号码 纠错能力越高,容纳信息越小,
纠错能力:L级:约可纠错7%的数据码字 M级:15% Q级:25% H级:30%
maven中
/** *使用zxing生成二维码 */ public class CreateQRCode { public static void main(String[] arge) throws WriterException, IOException{ int width = 300;//定义图片宽度 int height = 300;//定义图片高度 String format ="png";//定义图片格式 String content ="www.8664600.com";//定义二维码内容 ,加上http:// 可以实现页面跳转 //定义二维码参数 HashMap hints = new HashMap(); hints.put(EncodeHintType.CHARACTER_SET, "utf-8");//设置编码 //设置容错等级,等级越高,容量越小 hints.put(EncodeHintType.ERROR_CORRECTION,ErrorCorrectionLevel.M); hints.put(EncodeHintType.MARGIN,2);//设置边距 //生成矩阵 BitMatrix bitMatrix = new MultiFormatWriter().encode(content,BarcodeFormat.QR_CODE, width, height); //设置路径 Path file = new File("C:/Users/qqazl001/Desktop/Rui/ma.png").toPath(); MatrixToImageWriter.writeToPath(bitMatrix, format, file);//输出图像 } }
解析
MultiFormatReader formatReader=new MultiFormatReader();
File file=new File("F:/jjj/1.png");
BufferedImage image=ImageIO.read(file);
BinaryBitmap binaryBitmap=new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));
HashMap hints=new HashMap();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");//设置编码Result result=formatReader.read(binaryBitmap,hints);打印result.getText() result.toString(),result.getBarcodeFormat();QR Code 生成与解析Qrcode x=new Qrcode(); x.setQrcodeErrorCorrect('M'); x.setQrcodeEncodeMode('B'); x.setQrcodeVersion(7); String qrData="www.baidu.com"; int width=67+12*(7-1); int height=67+12*(7-1); BufferedImage bufferedImage=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB); Graphics2D gs=bufferedImage.createGraphics(); gs.setBackground(Color.WHITE); gs.setColor(Color.BLACK); gs.clearRect(0,0,width,height); int pixoff=2; byte[] d=qrData.getBytes("gbk2312"); if(d.length()>0&&d.length<120){ boolean[][] s=x.calQrcode(d); for(int i=0;i<s.length;i++){ for(int j=0;j<s.length;j++) { if(s[j][s]){ gs.fillRect(j*3+pixoff,i*3+pixoff,3,3); } } } } gs.dispose(); bufferedImage.flush(); ImageIO.write(bufferedImage,"png",new File("d:/qrcode.png")); public class ReadQRcode1 { public static void main(String[] args) throws Exception { //指定文件路径 File file=new File("E:/code/qrcode.png"); //读取验证码图片 BufferedImage bufferedImage=ImageIO.read(file); //调用方法 QRCodeDecoder codeDecoder=new QRCodeDecoder(); String result=new String(codeDecoder.decode(new MyQRCodeImage(bufferedImage)),"gb2312"); System.out.println("二维码的内容为:"+result); } }MyQRCodeImage 实现QRCodeImage接口 构造方法传递BufferdImage bufferdImageJQuery生成二维码:引入jquery.min.js 引入jquery.qrcode.min.js <div id="qrcode"></div><script type="text/javascript">Jquery("#qrcode").qrcode("www.baidu.com");</script>二维码纠错能力,可以加些图片;