java如何使用不同的ttf字体将utf8文本添加到图像中?
如何使用不同的utf8 ttf字体将utf8文本添加到图像中?(另一种语言)
我试过:
public static void main(String[] args) throws Exception {
final BufferedImage image = ImageIO.read(new File("E:/logo.png"));
Graphics g = image.getGraphics();
Font font = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("E:/BYekan.ttf"));
font.deriveFont(24F);
g.setFont(font);
g.setColor(Color.BLACK);
g.drawString("some utf8 text", 20, 20);
g.dispose();
ImageIO.write(image, "png", new File("E:/image.png"));}
我的问题是,当我执行这段代码时,结果显然是我的文本显示只是指向图像,如何修复这段代码
我的结果是: my created image
# 1 楼答案
你用了
canvases.drawText()
更新。 您可以将字体添加到“资源”文件夹,并使用它设置字体