【发布时间】:2011-01-25 03:47:59
【问题描述】:
我需要使用 java 2D 打印两个单词:“A”和“B”
字体大小 = 100;
“A”字体系列:Bodoni MT Poster Compressed
“B”字体系列:Arial
我写了下面的代码来做到这一点:
BufferedImage image = new BufferedImage(400, 300, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
{//fill bg color
g.setColor(new Color(255,255,255));
g.fillRect(0, 0, image.getWidth(), image.getHeight());
}
int FONT_SIZE=100;//set font size
{//print A
g.setColor(new Color(0,0,0));
g.setFont(new Font("Bodoni MT Poster Compressed", Font.PLAIN ,FONT_SIZE));
g.drawString("A",0,FONT_SIZE);
}
{//print B
g.setColor(new Color(0,0,0));
g.setFont(new Font("Arial", Font.PLAIN ,FONT_SIZE));
g.drawString("B",FONT_SIZE,FONT_SIZE);
}
g.dispose();
我得到结果图片:
但我需要这样(由 PhotoShop 制作):
我想g.drawString("B",FONT_SIZE,FONT_SIZE);的问题
如何获取字体 X 偏移宽度?
感谢您的帮助:)
【问题讨论】: