|
|
@ -15,6 +15,7 @@ import com.google.zxing.qrcode.QRCodeWriter; |
|
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; |
|
|
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; |
|
|
import org.apache.http.util.TextUtils; |
|
|
import org.apache.http.util.TextUtils; |
|
|
import org.junit.jupiter.api.Test; |
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
@ -22,9 +23,7 @@ import javax.imageio.ImageIO; |
|
|
import javax.servlet.ServletOutputStream; |
|
|
import javax.servlet.ServletOutputStream; |
|
|
import java.awt.*; |
|
|
import java.awt.*; |
|
|
import java.awt.image.BufferedImage; |
|
|
import java.awt.image.BufferedImage; |
|
|
import java.io.ByteArrayOutputStream; |
|
|
import java.io.*; |
|
|
import java.io.File; |
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
import java.nio.file.Path; |
|
|
import java.nio.file.Path; |
|
|
import java.nio.file.Paths; |
|
|
import java.nio.file.Paths; |
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
@ -169,7 +168,17 @@ public class CreateQrCodeUtil { |
|
|
Color color = new Color(0, 0, 0); |
|
|
Color color = new Color(0, 0, 0); |
|
|
g2d.setColor(color); |
|
|
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); |
|
|
int strWidth = g2d.getFontMetrics().stringWidth(code); |
|
|
//总长度减去文字长度的一半 (居中显示)
|
|
|
//总长度减去文字长度的一半 (居中显示)
|
|
|
|