Class QrConfig

java.lang.Object
org.miaixz.bus.extra.qrcode.QrConfig

public class QrConfig extends Object
二维码设置
Since:
Java 17+
Author:
Kimi Liu
  • Field Details

    • width

      protected int width
      宽度
    • height

      protected int height
      高度
    • foreColor

      protected Integer foreColor
      前景色(二维码颜色)
    • backColor

      protected Integer backColor
      背景色,默认白色,null表示透明
    • margin

      protected Integer margin
      边距0~4
    • qrVersion

      protected Integer qrVersion
      设置二维码中的信息量,可设置0-40的整数
    • errorCorrection

      protected com.google.zxing.qrcode.decoder.ErrorCorrectionLevel errorCorrection
      纠错级别
    • charset

      protected Charset charset
      编码
    • img

      protected Image img
      二维码中的Logo
    • imgRound

      protected double imgRound
      二维码logo圆角弧度,0~1,为长宽占比
    • ratio

      protected int ratio
      二维码中的Logo缩放的比例系数,如5表示长宽最小值的1/5
    • shapeHint

      protected com.google.zxing.datamatrix.encoder.SymbolShapeHint shapeHint
      DATA_MATRIX的符号形状
    • format

      protected com.google.zxing.BarcodeFormat format
      生成码的格式,默认为二维码
  • Constructor Details

    • QrConfig

      public QrConfig()
      构造,默认长宽为300
    • QrConfig

      public QrConfig(int width, int height)
      构造
      Parameters:
      width - 宽
      height - 高
  • Method Details

    • of

      public static QrConfig of()
      创建QrConfig
      Returns:
      QrConfig
    • of

      public static QrConfig of(int width, int height)
      创建QrConfig
      Parameters:
      width - 宽
      height - 高
      Returns:
      QrConfig
    • getWidth

      public int getWidth()
      获取宽度
      Returns:
      宽度
    • setWidth

      public QrConfig setWidth(int width)
      设置宽度
      Parameters:
      width - 宽度
      Returns:
      this
    • getHeight

      public int getHeight()
      获取高度
      Returns:
      高度
    • setHeight

      public QrConfig setHeight(int height)
      设置高度
      Parameters:
      height - 高度
      Returns:
      this;
    • getForeColor

      public int getForeColor()
      获取前景色
      Returns:
      前景色
    • setForeColor

      public QrConfig setForeColor(Color foreColor)
      设置前景色,例如:Ansi4BitColor.BLUE.getRGB()
      Parameters:
      foreColor - 前景色
      Returns:
      this
    • getBackColor

      public int getBackColor()
      获取背景色
      Returns:
      背景色
    • setBackColor

      public QrConfig setBackColor(Color backColor)
      设置背景色,例如:Ansi4BitColor.BLUE
      Parameters:
      backColor - 背景色,null表示透明背景
      Returns:
      this
    • getMargin

      public Integer getMargin()
      获取边距
      Returns:
      边距
    • setMargin

      public QrConfig setMargin(Integer margin)
      设置边距
      Parameters:
      margin - 边距
      Returns:
      this
    • getQrVersion

      public Integer getQrVersion()
      设置二维码中的信息量,可设置0-40的整数,二维码图片也会根据qrVersion而变化,0表示根据传入信息自动变化
      Returns:
      二维码中的信息量
    • setQrVersion

      public QrConfig setQrVersion(Integer qrVersion)
      设置二维码中的信息量,可设置0-40的整数,二维码图片也会根据qrVersion而变化,0表示根据传入信息自动变化
      Parameters:
      qrVersion - 二维码中的信息量
      Returns:
      this
    • getErrorCorrection

      public com.google.zxing.qrcode.decoder.ErrorCorrectionLevel getErrorCorrection()
      获取纠错级别
      Returns:
      纠错级别
    • setErrorCorrection

      public QrConfig setErrorCorrection(com.google.zxing.qrcode.decoder.ErrorCorrectionLevel errorCorrection)
      设置纠错级别
      Parameters:
      errorCorrection - 纠错级别
      Returns:
      this
    • setEnableEci

      public void setEnableEci(boolean enableEci)
      是否开启ECI编码 如果enableEci=false,则二维码中不包含ECI信息,即:charset字符编码设置为null, 二维码为英文字符,保持false最佳 如果enableEci=true,则二维码中包含ECI信息,即:按照charset编码进行设置, 二维码为包含中文,保持true最佳,否则会中文乱码

      二维码编码有ECI模式和非ECI模式的情况之分,在ECI模式下第一个字节是用作编码标识,而非ECI模式下直接就是数据流。 ECI模式其实是更好的方案,这样子解码的时候可以根据标识采用不同的编码方式。而非ECI模式只能按照一种统一的方式处理了。 但是由于部分设备不支持ECI模式,所以就出现了无法识别的情况。 使用扫码桩/扫码枪,可能会出现\000026的字符。使用手机扫描、其他二维码解析软件扫描,则不会出现。

      ECI编码表可以看出UTF-8就是对应"\000026"(对应数字22)

      总结建议:如果二维码内容全是字符,没有中文,就不用使用UTF-8等格式进行编码,只有使用中文等特殊符号才需要编码

      Parameters:
      enableEci - 是否开启ECI
      See Also:
      • EncodeHintType.PDF417_AUTO_ECI
    • getCharset

      public Charset getCharset()
      获取编码
      Returns:
      编码
    • setCharset

      public QrConfig setCharset(Charset charset)
      设置编码
      Parameters:
      charset - 编码
      Returns:
      this
    • getImg

      public Image getImg()
      获取二维码中的Logo
      Returns:
      Logo图片
    • setImg

      public QrConfig setImg(String imgPath)
      设置二维码中的Logo文件
      Parameters:
      imgPath - 二维码中的Logo路径
      Returns:
      this;
    • setImg

      public QrConfig setImg(byte[] imageBytes)
      设置二维码中的Logo文件
      Parameters:
      imageBytes - 二维码中的Logo图片bytes表示形式
      Returns:
      this;
    • setImg

      public QrConfig setImg(File imgFile)
      设置二维码中的Logo文件
      Parameters:
      imgFile - 二维码中的Logo
      Returns:
      this;
    • setImg

      public QrConfig setImg(Image img)
      设置二维码中的Logo
      Parameters:
      img - 二维码中的Logo
      Returns:
      this;
    • getImgRound

      public double getImgRound()
      获取二维码logo圆角弧度,0~1,为长宽占比
      Returns:
      二维码logo圆角弧度,0~1,为长宽占比
    • setImgRound

      public QrConfig setImgRound(double imgRound)
      设置二维码logo圆角弧度,0~1,为长宽占比
      Parameters:
      imgRound - 二维码logo圆角弧度,0~1,为长宽占比
      Returns:
      this
    • getRatio

      public int getRatio()
      获取二维码中的Logo缩放的比例系数,如5表示长宽最小值的1/5
      Returns:
      二维码中的Logo缩放的比例系数,如5表示长宽最小值的1/5
    • setRatio

      public QrConfig setRatio(int ratio)
      设置二维码中的Logo缩放的比例系数,如5表示长宽最小值的1/5
      Parameters:
      ratio - 二维码中的Logo缩放的比例系数,如5表示长宽最小值的1/5
      Returns:
      this;
    • setShapeHint

      public QrConfig setShapeHint(com.google.zxing.datamatrix.encoder.SymbolShapeHint shapeHint)
      设置DATA_MATRIX的符号形状
      Parameters:
      shapeHint - DATA_MATRIX的符号形状
      Returns:
      this
    • getFormat

      public com.google.zxing.BarcodeFormat getFormat()
      获取码格式
      Returns:
      码格式,默认为二维码
    • setFormat

      public QrConfig setFormat(com.google.zxing.BarcodeFormat format)
      设置码格式,默认二维码
      Parameters:
      format - 码格式
      Returns:
      this
    • toHints

      public HashMap<com.google.zxing.EncodeHintType,Object> toHints()
      转换为Zxing的二维码配置
      Returns:
      配置