解决方式1:
windows上的字体拷贝到linux上。
解决方式2:
本地java读写字体。 参考地址: https://blog.csdn.net/qq_36098927/article/details/107921160
https://blog.csdn.net/echohawk/article/details/105452525
网上时候还有这个问题,不过我还没遇到: https://blog.csdn.net/weixin_34294809/article/details/114301980?utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.no_search_link
3.个人解决此问题的完整代码:
public InputStream createDistributorSharePosterInputstream(String bgOriginUrl, String wechatNickName, String wechatAvatarUrl, String wechatRecomQrcodeUrl) {
try {
BufferedImage bimg = getUrlByBufferedImage(bgOriginUrl);
Font font1 = null;
GraphicsEnvironment localGraphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
Font font = Font.createFont(Font.TRUETYPE_FONT, ImageGenerateUtil.class.getResourceAsStream("/font/msyhbd.ttf"));
font1 = font.deriveFont(Font.BOLD,24f);
localGraphicsEnvironment.registerFont(font);
Graphics2D g2d = localGraphicsEnvironment.createGraphics(bimg);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
BufferedImage userLogo = getSque(getUrlByBufferedImage(wechatAvatarUrl));
g2d.drawImage(setRadius(userLogo, 3), 336, 1064, 80, 80, null);
g2d.setFont(font1);
g2d.setColor(Color.WHITE);
drawString(wechatNickName, bimg, g2d, font1, 1174);
g2d.setFont(font1);
g2d.setColor(Color.WHITE);
drawString("邀请您成为飞碟推荐官", bimg, g2d, font1, 1202);
Image sunCodeUrlImage = getUrlByBufferedImage(wechatRecomQrcodeUrl);
g2d.drawImage(sunCodeUrlImage, 604, 1258, 100, 100, null);
g2d.dispose();
return upload(bimg);
} catch (Exception e) {
e.printStackTrace();
log.info("goodsCard:{}", e.getMessage());
}
return null;
}
完
|