mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
!722 修复QrCodeUtil对于DATA_MATRIX生成的形状随机不可指定的功能完善
Merge pull request !722 from Husky/v5-dev
This commit is contained in:
commit
305e0fca07
@ -5,6 +5,7 @@ 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.datamatrix.encoder.SymbolShapeHint;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
|
||||
import java.awt.Color;
|
||||
@ -44,6 +45,10 @@ public class QrConfig {
|
||||
protected Image img;
|
||||
/** 二维码中的Logo缩放的比例系数,如5表示长宽最小值的1/5 */
|
||||
protected int ratio = 6;
|
||||
/**
|
||||
* DATA_MATRIX的符号形状
|
||||
*/
|
||||
protected SymbolShapeHint shapeHint = SymbolShapeHint.FORCE_NONE;
|
||||
|
||||
/**
|
||||
* 创建QrConfig
|
||||
@ -326,6 +331,17 @@ public class QrConfig {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置DATA_MATRIX的符号形状
|
||||
*
|
||||
* @param shapeHint DATA_MATRIX的符号形状
|
||||
* @return this;
|
||||
*/
|
||||
public QrConfig setShapeHint(SymbolShapeHint shapeHint) {
|
||||
this.shapeHint = shapeHint;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换为Zxing的二维码配置
|
||||
*
|
||||
@ -357,6 +373,7 @@ public class QrConfig {
|
||||
}
|
||||
|
||||
hints.put(EncodeHintType.ERROR_CORRECTION, value);
|
||||
hints.put(EncodeHintType.DATA_MATRIX_SHAPE, shapeHint);
|
||||
}
|
||||
if (null != this.margin) {
|
||||
hints.put(EncodeHintType.MARGIN, this.margin);
|
||||
|
@ -5,6 +5,7 @@ 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.datamatrix.encoder.SymbolShapeHint;
|
||||
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
@ -84,16 +85,28 @@ public class QrCodeUtilTest {
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void decodeTest3(){
|
||||
public void decodeTest3() {
|
||||
final String decode = QrCodeUtil.decode(ImgUtil.read("d:/test/qr_a.png"), false, true);
|
||||
Console.log(decode);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pdf417Test(){
|
||||
public void pdf417Test() {
|
||||
final BufferedImage image = QrCodeUtil.generate("content111", BarcodeFormat.PDF_417, QrConfig.create());
|
||||
Assert.assertNotNull(image);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateDataMatrixTest() {
|
||||
QrConfig qrConfig = QrConfig.create();
|
||||
qrConfig.setShapeHint(SymbolShapeHint.FORCE_RECTANGLE);
|
||||
final BufferedImage image = QrCodeUtil.generate("content111", BarcodeFormat.DATA_MATRIX, qrConfig);
|
||||
Assert.assertNotNull(image);
|
||||
QrConfig config = QrConfig.create();
|
||||
config.setShapeHint(SymbolShapeHint.FORCE_SQUARE);
|
||||
final BufferedImage imageSquare = QrCodeUtil.generate("content111", BarcodeFormat.DATA_MATRIX, qrConfig);
|
||||
Assert.assertNotNull(imageSquare);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user