1 package com.ideal.common.util;
2
3 import java.awt.image.BufferedImage;
4 import java.io.File;
5 import java.io.FileInputStream;
6 import java.io.FileNotFoundException;
7 import java.io.FileOutputStream;
8 import java.util.UUID;
9
10 import net.glxn.qrgen.core.image.ImageType;
11 import net.glxn.qrgen.javase.QRCode;
12
13 /**
14 *
15 * 二维码生成工具类
16 *@author:daipeng
17 *@date:2017年6月15日
18 */
19 public class MyQRCodeUtils {
20 /**
21 *
22 *
23 * @Title: getCode
24 * @Description: 生成二维码
25 * @author:daipeng
26 * @param: @param mCode 二维码的url地址
27 * @param: @param pathName 二维码全路径名称唯一,否则会覆盖
28 * @param: @return
29 * @param: @throws Exception
30 * @return: String
31 * @throws
32 */
33 public static void getCode(String mCode,String pathName) throws Exception{
34 File qrCode = QRCode.from(mCode).withCharset("UTF-8").to(ImageType.PNG).withSize(250, 250).file();
35 FileInputStream inputStream = new FileInputStream(qrCode);
36 FileOutputStream outputStream = new FileOutputStream(new File(pathName+".png"));
37 byte[] buffer = new byte[1024];
38 int i = -1;
39 while ((i = inputStream.read(buffer)) != -1) {
40 outputStream.write(buffer, 0, i);
41 }
42 outputStream.flush();
43 outputStream.close();
44 inputStream.close();
45 }
46
47 public static File getCode2(String mCode,String pathName) throws Exception{
48 File qrCode = QRCode.from(mCode).withCharset("UTF-8").to(ImageType.PNG).withSize(250, 250).file();
49 return qrCode;
50 }
51
52
53 public static void main(String[] args) throws Exception {
54 String mCode = "advd";
55 String pathName = "E:\\1";
56 getCode(mCode,pathName);
57 }
58 }