一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|JAVA教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|

服務(wù)器之家 - 編程語言 - JAVA教程 - java二維碼生成的方法

java二維碼生成的方法

2020-11-10 16:44ITqingliang JAVA教程

這篇文章主要為大家詳細(xì)介紹了java二維碼生成的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了java二維碼的實(shí)現(xiàn)代碼,供大家參考,具體內(nèi)容如下

這次用到的jar包是zxing,沒有用到core的jar包
先導(dǎo)入zxing.jar包

生成二維碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package cn.huse.erweima;
 
import java.io.File;
import java.util.HashMap;
 
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
 
/**
 * 生成二維碼
 *
 */
public class CreateQRCode {
 
 public static void main(String[] args) {
 int width = 300;
 int height = 300;
 
 String format = "gif";
 String content = "www.baidu.com";
 
 //定義二維碼的參數(shù)
 HashMap hints = new HashMap<>();
 hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
 hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.M);
 try {
  BitMatrix matrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height,hints);
  File file = new File("e:"+File.separator+"new.gif");
  MatrixToImageWriter.writeToFile(matrix, format, file);
 } catch (Exception e) {
  e.printStackTrace();
 }
 }
 
}

解析二維碼

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package cn.huse.erweima;
 
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import javax.imageio.ImageIO;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.NotFoundException;
import com.google.zxing.Result;
import com.google.zxing.client.j2se.BufferedImageLuminanceSource;
import com.google.zxing.common.HybridBinarizer;
 
//解析二維碼
public class ReadQRCode {
 
 public static void main(String[] args) {
 
 MultiFormatReader formatReader = new MultiFormatReader();
 File file = new File("e:"+File.separator+"new.gif");
 try {
  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.decode(binaryBitmap,hints);
  System.out.println(result.toString());
  System.out.println(result.getBarcodeFormat());
  System.out.println(result.getText());
 } catch (NotFoundException e) {
  e.printStackTrace();
 } catch (IOException e) {
  e.printStackTrace();
 }
 }
 
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 欧美日韩国产在线人成dvd | 日韩精品视频福利资源站 | xx×日本老太| 传说之下羊妈挤羊奶网站 | 美女张开腿让我了一夜 | 好爽好紧小雪别夹小说 | china国产bbw| 四虎永久免费地址ww417 | 免费看国产精品麻豆 | 亚洲 综合 欧美在线 热 | 99re这里只有精品视频在线观看 | 国产精品高清一区二区三区不卡 | 国产亚洲精品精品国产亚洲综合 | 国产一卡2卡3卡四卡高清 | 果冻传媒91 | 欧美在线观看一区二区三 | 色多多视频网站 | 99久久综合 | 日本免费不卡在线一区二区三区 | 亚洲欧美日韩一区成人 | 男生操女生动态图 | 日韩美女强理论片 | 天天中文 | 亚洲AV 日韩 国产 有码 | 欧美人与物videos另类3d | 波多野结衣被绝伦强在线观看 | 日本一区视频在线 | 亚洲美女aⅴ久久久91 | 男同桌扒开女同桌胸罩喝奶 | 成年人在线视频观看 | 香蕉免费一区二区三区在线观看 | 3d美女触手怪爆羞羞漫画 | 特级淫片欧美高清视频蜜桃 | h杯奶水太多h | 高清国产激情视频在线观看 | 青草视频网址 | 12345国产精品高清在线 | 国产欧美日韩高清专区ho | 久久re6热在线视频 久久AV喷吹AV高潮欧美 | 五月天婷婷网亚洲综合在线 | 日韩欧美在线观看综合网另类 |