diff --git a/src/main/java/com/dreamchaser/depository_manage/utils/CreateQrCodeUtil.java b/src/main/java/com/dreamchaser/depository_manage/utils/CreateQrCodeUtil.java index a213718d..ce20c394 100644 --- a/src/main/java/com/dreamchaser/depository_manage/utils/CreateQrCodeUtil.java +++ b/src/main/java/com/dreamchaser/depository_manage/utils/CreateQrCodeUtil.java @@ -15,6 +15,7 @@ import com.google.zxing.qrcode.QRCodeWriter; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; import org.apache.http.util.TextUtils; import org.junit.jupiter.api.Test; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -22,9 +23,7 @@ import javax.imageio.ImageIO; import javax.servlet.ServletOutputStream; import java.awt.*; import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; +import java.io.*; import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; @@ -169,7 +168,17 @@ public class CreateQrCodeUtil { Color color = new Color(0, 0, 0); g2d.setColor(color); // 字体、字型、字号 - g2d.setFont(new Font("Droid Sans", Font.PLAIN, 16)); + Font font = null; + try { + ClassPathResource classPathResource = new ClassPathResource("static/lib/font-awesome-4.7.0/fonts/simsun.ttc"); + InputStream inputStream =classPathResource.getInputStream(); + font = Font.createFont(Font.PLAIN, inputStream); + font = font.deriveFont(Font.PLAIN, 16); + } catch (Exception e) { + font = new Font("Droid Sans", Font.PLAIN, 16); + } + g2d.setFont(font); + //文字长度 int strWidth = g2d.getFontMetrics().stringWidth(code); //总长度减去文字长度的一半 (居中显示) diff --git a/src/main/resources/static/lib/font-awesome-4.7.0/fonts/simsun.ttc b/src/main/resources/static/lib/font-awesome-4.7.0/fonts/simsun.ttc new file mode 100644 index 00000000..5f22ce3f Binary files /dev/null and b/src/main/resources/static/lib/font-awesome-4.7.0/fonts/simsun.ttc differ