码迷,mamicode.com
首页 > 其他好文 > 详细

zxing生成二维码

时间:2017-09-21 13:26:06      阅读:167      评论:0      收藏:0      [点我收藏+]

标签:pid   write   []   depend   dimens   util   shm   put   pack   

依赖包zxing

<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.0</version>
</dependency>

<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>

测试代码
package com.fz;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.client.j2se.MatrixToImageWriter;
import com.google.zxing.common.BitMatrix;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;


public class TwoDimensionCode {
public static void main(String[] args) {
int width = 200;
int height = 200;
String format = "png";
String content = "二维码内容";
Map<EncodeHintType, Object> hints = new HashMap<EncodeHintType, Object>();
hints.put(EncodeHintType.CHARACTER_SET, "utf-8");
try {
BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, width, height, hints);
MatrixToImageWriter.writeToFile(bitMatrix, format, new File("c://x.png"));
System.out.println("文件已经生成在C盘");
} catch (WriterException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}

}

}

zxing生成二维码

标签:pid   write   []   depend   dimens   util   shm   put   pack   

原文地址:http://www.cnblogs.com/fie666/p/7567841.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!