既存の画像の上にテキストを書いていますが、フォントがあまり鮮明ではありません。画像の上にテキストを書くときにフォントの見栄えを良くするのに役立つ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);
}
}