mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
优化QrCodeUtil
This commit is contained in:
parent
62735daa36
commit
e6fc469e60
@ -358,7 +358,7 @@ public class QrCodeUtil {
|
|||||||
*/
|
*/
|
||||||
public static BufferedImage generate(String content, BarcodeFormat format, QrConfig config) {
|
public static BufferedImage generate(String content, BarcodeFormat format, QrConfig config) {
|
||||||
final BitMatrix bitMatrix = encode(content, format, config);
|
final BitMatrix bitMatrix = encode(content, format, config);
|
||||||
final BufferedImage image = toImage(bitMatrix, config.foreColor, config.backColor);
|
final BufferedImage image = toImage(bitMatrix, config.foreColor != null ? config.foreColor : 0xFF000000, config.backColor);
|
||||||
final Image logoImg = config.img;
|
final Image logoImg = config.img;
|
||||||
if (null != logoImg && BarcodeFormat.QR_CODE == format) {
|
if (null != logoImg && BarcodeFormat.QR_CODE == format) {
|
||||||
// 只有二维码可以贴图
|
// 只有二维码可以贴图
|
||||||
|
@ -44,6 +44,18 @@ public class QrCodeUtilTest {
|
|||||||
String path = FileUtil.isWindows() ? "d:/test/qrcodeCustom.png" : "~/Desktop/hutool/qrcodeCustom.png";
|
String path = FileUtil.isWindows() ? "d:/test/qrcodeCustom.png" : "~/Desktop/hutool/qrcodeCustom.png";
|
||||||
QrCodeUtil.generate("https://hutool.cn/", config, FileUtil.touch(path));
|
QrCodeUtil.generate("https://hutool.cn/", config, FileUtil.touch(path));
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
|
// @Ignore
|
||||||
|
public void generateNoCustomColorTest() {
|
||||||
|
QrConfig config = new QrConfig();
|
||||||
|
config.setMargin(0);
|
||||||
|
config.setForeColor(null);
|
||||||
|
// 背景色透明
|
||||||
|
config.setBackColor(null);
|
||||||
|
config.setErrorCorrection(ErrorCorrectionLevel.H);
|
||||||
|
String path = FileUtil.isWindows() ? "d:/test/qrcodeCustom.png" : "~/Desktop/hutool/qrcodeCustom.png";
|
||||||
|
QrCodeUtil.generate("https://hutool.cn/", config, FileUtil.touch(path));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
@Ignore
|
||||||
@ -143,6 +155,18 @@ public class QrCodeUtilTest {
|
|||||||
Assert.assertNotNull(asciiArt);
|
Assert.assertNotNull(asciiArt);
|
||||||
System.out.println(asciiArt);
|
System.out.println(asciiArt);
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
|
public void generateAsciiArtNoCustomColorTest() {
|
||||||
|
QrConfig qrConfig = QrConfig.create()
|
||||||
|
.setForeColor(null)
|
||||||
|
.setBackColor(null)
|
||||||
|
.setWidth(0)
|
||||||
|
.setHeight(0).setMargin(1);
|
||||||
|
String asciiArt = QrCodeUtil.generateAsAsciiArt("https://hutool.cn/",qrConfig);
|
||||||
|
Assert.assertNotNull(asciiArt);
|
||||||
|
System.out.println(asciiArt);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void generateToFileTest() {
|
public void generateToFileTest() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user