CreateQRCode.java
int width =300;
int height=300;
String format="png";//图片格式
String content="内容"//二维码扫出来的内容
//定义二维码的参数
通过一个HashMap hints= new HashMap();
hints.put(EncodeHintType.CHARACTER_SET,"utf-8")//定义字符集编码
hints.put(EncodeHintType.ERROR_CONRRECTION,ErrorcorrectionLevel.M)//定义二维码的大小 清晰程度。(M,L,H)
hints.put(EncodeHintType.MARGIN,2)//设置二维码的边距
//生成二维码
BitMatrix bitMatrix =new MultiFormatWrites().encode(content 定义信息, BarcodeFormat.QR_CODE定义二维码的类型,width,height,hints)//记得捕捉异常
Path file=new File("路径").toPath;//定义一个路径
MatrixToImageWiter.路径或者是数据流(bitMatrix,format,file(路径))
/** *使用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";//定义二维码内容 //定义二维码参数 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);//输出图像 } }