mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix qr test
This commit is contained in:
@@ -313,9 +313,10 @@ public class QrCodeUtil {
|
||||
// 默认配置
|
||||
config = new QrConfig();
|
||||
}
|
||||
|
||||
BitMatrix bitMatrix;
|
||||
try {
|
||||
bitMatrix = multiFormatWriter.encode(content, format, config.width, config.height, config.toHints());
|
||||
bitMatrix = multiFormatWriter.encode(content, format, config.width, config.height, config.toHints(format));
|
||||
} catch (WriterException e) {
|
||||
throw new QrCodeException(e);
|
||||
}
|
||||
|
@@ -3,6 +3,7 @@ package cn.hutool.extra.qrcode;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.EncodeHintType;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
|
||||
@@ -331,13 +332,31 @@ public class QrConfig {
|
||||
* @return 配置
|
||||
*/
|
||||
public HashMap<EncodeHintType, Object> toHints() {
|
||||
return toHints(BarcodeFormat.QR_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Zxing的二维码配置
|
||||
*
|
||||
* @param format 格式,根据格式不同,{@link #errorCorrection}的值类型有所不同
|
||||
* @return 配置
|
||||
*/
|
||||
public HashMap<EncodeHintType, Object> toHints(BarcodeFormat format) {
|
||||
// 配置
|
||||
final HashMap<EncodeHintType, Object> hints = new HashMap<>();
|
||||
if (null != this.charset) {
|
||||
hints.put(EncodeHintType.CHARACTER_SET, charset.toString().toLowerCase());
|
||||
}
|
||||
if (null != this.errorCorrection) {
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, this.errorCorrection);
|
||||
Object value;
|
||||
if(BarcodeFormat.AZTEC == format || BarcodeFormat.PDF_417 == format){
|
||||
// issue#I4FE3U@Gitee
|
||||
value = this.errorCorrection.getBits();
|
||||
} else {
|
||||
value = this.errorCorrection;
|
||||
}
|
||||
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, value);
|
||||
}
|
||||
if (null != this.margin) {
|
||||
hints.put(EncodeHintType.MARGIN, this.margin);
|
||||
|
@@ -4,6 +4,7 @@ import cn.hutool.core.codec.Base64;
|
||||
import cn.hutool.core.img.ImgUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.lang.Console;
|
||||
import com.google.zxing.BarcodeFormat;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
@@ -87,4 +88,10 @@ public class QrCodeUtilTest {
|
||||
final String decode = QrCodeUtil.decode(ImgUtil.read("d:/test/qr_a.png"), false, true);
|
||||
Console.log(decode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pdf417Test(){
|
||||
final BufferedImage image = QrCodeUtil.generate("content111", BarcodeFormat.PDF_417, QrConfig.create());
|
||||
Assert.assertNotNull(image);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user