我在现有图像上面写了一些文字,字体不是很清晰。是否有一些设置,使用Graphics2D或Font类,有助于使字体在图像上面写文字时看起来更好? Dante字体在我写的时候并不像Dante那样出现。我试过使用抗锯齿但它没有效果(参见setRenderingHint)。无论有没有RenderingHint设置,图像都是相同的。有什么建议?
public class ImageCreator{
public void createImage(String text){
Graphics2D g = img.createGraphics(); //img is a BufferedImage read in from file system
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
Font fnt=new Font("Dante",1,20);
Color fntC = new Color(4, 4, 109);
g.setColor(fntC);
g.setFont(fnt);
Dimension d = new Dimension(200, 113);
drawCenteredString(text, d.width, d.height, g);
}
public static void drawCenteredString(String s, int w, int h, Graphics g) {
FontMetrics fm = g.getFontMetrics();
int x = (w - fm.stringWidth(s)) / 2;
int y = (fm.getAscent() + (h - (fm.getAscent() + fm.getDescent())) / 2);
g.drawString(s, x, y);
}
}