java生成二维码/java解析二维码
生活随笔
收集整理的這篇文章主要介紹了
java生成二维码/java解析二维码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
二維碼的優缺點
優點:1. 高密度編碼,信息容量大;2.編碼范圍廣;3.容錯能力強;4.譯碼可靠性高;5.可引入加密措施;6.成本低,易制作,持久耐用。
缺點:1.二維碼技術成為手機病毒、釣魚網站傳播的新渠道;2.信息容易泄露。
三大國際標準
1.PDF417:不支持中文;
2.DM:專利未公開,需要支付專利費用;
3.QR Code:專利公開,支持中文。
其中,QR Code具有識讀速度快、數據密度大、占用空間小的優勢。
糾錯能力
L級:約可糾錯7%的數據碼字
M級:約可糾錯15%的數據碼字
Q級:約可糾錯25%的數據碼字
H級:約可糾錯30%的數據碼字
ZXing生成/讀取二維碼
package com.demo.test;import com.google.zxing.*; import com.google.zxing.client.j2se.BufferedImageLuminanceSource; 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.image.BufferedImage; import java.io.File; import java.nio.file.Path; import java.util.HashMap;/*** Created by zhangxiao on 2018/11/23* Descr: 生成二維碼**/ public class CreateQRCode {public static void main(String[] args) throws Exception {final int width = 300;final int height = 300;final String format = "png";final String content = "https://www.baidu.com";//定義二維碼的參數HashMap hints = new HashMap();hints.put(EncodeHintType.CHARACTER_SET, "utf-8");//L級:約可糾錯7%的數據碼字,M級:約可糾錯15%的數據碼字,Q級:約可糾錯25%的數據碼字,H級:約可糾錯30%的數據碼字 hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.Q);hints.put(EncodeHintType.MARGIN, 2);//生成二維碼BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);Path file = new File("D:/img.png").toPath();MatrixToImageWriter.writeToPath(bitMatrix, format, file);System.out.println("生成成功,路徑:" + file.toString());System.out.println("------------------------------");//解析二維碼MultiFormatReader formatReader = new MultiFormatReader();BufferedImage image = ImageIO.read(file.toFile());BinaryBitmap binaryBitmap = new BinaryBitmap(new HybridBinarizer(new BufferedImageLuminanceSource(image)));Result result = formatReader.decode(binaryBitmap, hints);System.out.println("二維碼解析結果:" + result.toString());System.out.println("二維碼的格式:" + result.getBarcodeFormat());System.out.println("二維碼的文本內容:" + result.getText());}}?
轉載于:https://www.cnblogs.com/sonder/p/10007876.html
總結
以上是生活随笔為你收集整理的java生成二维码/java解析二维码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [SQL Server]无法创建 SSI
- 下一篇: MySQL 中的 FOUND_ROWS(