zoukankan      html  css  js  c++  java
  • zxing生成二维码

    依赖包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();
    }

    }

    }
  • 相关阅读:
    qt install (1)
    learning rewind func
    learning strrchr func
    learning memchr func
    git lfs setpu(4)
    大端与小端
    git branch/meger step(3)
    git log/show/HEAD step(2)
    调用外部EXE文件
    获取计算机上的所有进程
  • 原文地址:https://www.cnblogs.com/fie666/p/7567841.html
Copyright © 2011-2022 走看看