Package org.miaixz.bus.extra.qrcode
Class QrCodeKit
java.lang.Object
org.miaixz.bus.extra.qrcode.QrCodeKit
基于Zxing的二维码工具类,支持:
- 二维码生成和识别,见
BarcodeFormat.QR_CODE - 条形码生成和识别,见
BarcodeFormat.CODE_39等很多标准格式
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String将二维码或条形码图片解码为文本static String将二维码或条形码图片解码为文本 此方法会尝试使用HybridBinarizer和GlobalHistogramBinarizer两种模式解析 需要注意部分二维码如果不带logo,使用PureBarcode模式会解析失败,此时须设置此选项为false。static String将二维码或条形码图片解码为文本 此方法会尝试使用HybridBinarizer和GlobalHistogramBinarizer两种模式解析 需要注意部分二维码如果不带logo,使用PureBarcode模式会解析失败,此时须设置此选项为false。static String解码二维码或条形码图片为文本static Stringdecode(InputStream qrCodeInputstream) 解码二维码或条形码图片为文本static com.google.zxing.common.BitMatrixencode(CharSequence content, QrConfig config) 将文本内容编码为条形码或二维码static BufferedImage生成二维码图片static File生成二维码到文件,二维码图片格式取决于文件的扩展名static voidgenerate(String content, int width, int height, String imageType, OutputStream out) 生成二维码到输出流static BufferedImage生成二维码或条形码图片 只有二维码时QrConfig中的图片才有效static File生成二维码到文件,二维码图片格式取决于文件的扩展名static voidgenerate(String content, QrConfig config, String imageType, OutputStream out) 生成二维码到输出流static StringgenerateAsAsciiArt(String content, QrConfig qrConfig) 生成ASCII Art字符画形式的二维码static StringgenerateAsBase64DataUri(String content, QrConfig qrConfig, String imageType) 生成 Base64 编码格式的二维码,以 String 形式表示static StringgenerateAsSvg(String content, QrConfig qrConfig) static byte[]generatePng(String content, int width, int height) 生成PNG格式的二维码图片,以byte[]形式表示static byte[]generatePng(String content, QrConfig config) 生成PNG格式的二维码图片,以byte[]形式表示static StringtoAsciiArt(com.google.zxing.common.BitMatrix bitMatrix, QrConfig qrConfig) BitMatrix转ASCII Art字符画形式的二维码static BufferedImageBitMatrix转BufferedImagestatic StringBitMatrix转SVG(字符串)
-
Field Details
-
QR_TYPE_SVG
SVG矢量图格式- See Also:
-
QR_TYPE_TXT
Ascii Art字符画文本- See Also:
-
-
Constructor Details
-
QrCodeKit
public QrCodeKit()
-
-
Method Details
-
generateAsBase64DataUri
生成 Base64 编码格式的二维码,以 String 形式表示输出格式为: data:image/[type];base64,[data]
- Parameters:
content- 内容qrConfig- 二维码配置,包括宽度、高度、边距、颜色等imageType- 图片类型(图片扩展名),见ImageKit- Returns:
- 图片 Base64 编码字符串
-
generatePng
生成PNG格式的二维码图片,以byte[]形式表示- Parameters:
content- 内容width- 宽度height- 高度- Returns:
- 图片的byte[]
-
generatePng
生成PNG格式的二维码图片,以byte[]形式表示- Parameters:
content- 内容config- 二维码配置,包括宽度、高度、边距、颜色等- Returns:
- 图片的byte[]
-
generate
生成二维码到文件,二维码图片格式取决于文件的扩展名- Parameters:
content- 文本内容width- 宽度height- 高度targetFile- 目标文件,扩展名决定输出格式- Returns:
- 目标文件
-
generate
生成二维码到文件,二维码图片格式取决于文件的扩展名- Parameters:
content- 文本内容config- 二维码配置,包括宽度、高度、边距、颜色等targetFile- 目标文件,扩展名决定输出格式- Returns:
- 目标文件
-
generate
public static void generate(String content, int width, int height, String imageType, OutputStream out) 生成二维码到输出流- Parameters:
content- 文本内容width- 宽度height- 高度imageType- 图片类型(图片扩展名),见ImageKitout- 目标流
-
generate
生成二维码到输出流- Parameters:
content- 文本内容config- 二维码配置,包括宽度、高度、边距、颜色等imageType- 图片类型(图片扩展名),见ImageKitout- 目标流
-
generate
生成二维码图片- Parameters:
content- 文本内容width- 宽度height- 高度- Returns:
- 二维码图片(黑白)
-
generate
生成二维码或条形码图片 只有二维码时QrConfig中的图片才有效- Parameters:
content- 文本内容config- 二维码配置,包括宽度、高度、边距、颜色等- Returns:
- 二维码图片(黑白)
-
encode
将文本内容编码为条形码或二维码- Parameters:
content- 文本内容config- 二维码配置,包括宽度、高度、边距、颜色、格式等- Returns:
BitMatrix
-
decode
解码二维码或条形码图片为文本- Parameters:
qrCodeInputstream- 二维码输入流- Returns:
- 解码文本
-
decode
解码二维码或条形码图片为文本- Parameters:
qrCodeFile- 二维码文件- Returns:
- 解码文本
-
decode
将二维码或条形码图片解码为文本- Parameters:
image-Image二维码图片- Returns:
- 解码后的文本
-
decode
将二维码或条形码图片解码为文本 此方法会尝试使用HybridBinarizer和GlobalHistogramBinarizer两种模式解析 需要注意部分二维码如果不带logo,使用PureBarcode模式会解析失败,此时须设置此选项为false。- Parameters:
image-Image二维码图片isTryHarder- 是否优化精度isPureBarcode- 是否使用复杂模式,扫描带logo的二维码设为true- Returns:
- 解码后的文本
-
decode
将二维码或条形码图片解码为文本 此方法会尝试使用HybridBinarizer和GlobalHistogramBinarizer两种模式解析 需要注意部分二维码如果不带logo,使用PureBarcode模式会解析失败,此时须设置此选项为false。- Parameters:
image-Image二维码图片hints- 自定义扫码配置,包括算法、编码、复杂模式等- Returns:
- 解码后的文本
-
toImage
public static BufferedImage toImage(com.google.zxing.common.BitMatrix matrix, int foreColor, Integer backColor) BitMatrix转BufferedImage- Parameters:
matrix- BitMatrixforeColor- 前景色backColor- 背景色(null表示透明背景)- Returns:
- BufferedImage
-
generateAsSvg
- Parameters:
content- 内容qrConfig- 二维码配置,包括宽度、高度、边距、颜色等- Returns:
- SVG矢量图(字符串)
-
toSVG
BitMatrix转SVG(字符串)- Parameters:
matrix- BitMatrixconfig-QrConfig- Returns:
- SVG矢量图(字符串)
-
generateAsAsciiArt
生成ASCII Art字符画形式的二维码- Parameters:
content- 内容qrConfig- 二维码配置,仅宽度、高度、边距配置有效- Returns:
- ASCII Art字符画形式的二维码
-
toAsciiArt
BitMatrix转ASCII Art字符画形式的二维码- Parameters:
bitMatrix- BitMatrixqrConfig- QR设置- Returns:
- ASCII Art字符画形式的二维码
-