修改了资源路径6

This commit is contained in:
wucongxing8150 2025-08-01 11:32:54 +08:00
parent 7a060c442e
commit 492eef5bc0
2 changed files with 13 additions and 6 deletions

View File

@ -11,11 +11,8 @@ import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.*;
import java.text.SimpleDateFormat;
import java.io.File;
import java.util.Date;
import java.util.Objects;
import org.springframework.core.io.ClassPathResource;
@ -43,7 +40,8 @@ public class CertService {
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
// 1. 添加证书编号
Font font = new Font("Microsoft YaHei", Font.PLAIN, 40); // 可根据模板调整大小
Font font = loadFont("static/cert/msyh.ttf", 40f);
// Font font = new Font("Microsoft YaHei", Font.PLAIN, 40); // 可根据模板调整大小
g2d.setFont(font);
Color customColor = Color.decode("#008983");
@ -266,5 +264,14 @@ public class CertService {
}
}
public static Font loadFont(String path, float size) {
try {
ClassPathResource resource = new ClassPathResource(path);
try (InputStream inputStream = resource.getInputStream()) {
return Font.createFont(Font.TRUETYPE_FONT, inputStream).deriveFont(size);
}
} catch (Exception e) {
throw new RuntimeException("字体加载失败: " + path, e);
}
}
}

Binary file not shown.