由于这里画图是根据字体的基线进行定位
所以top,也就是最终的高度需要指定高度加上descent的高度+字的高度/2
即
final_Y = Y+strHeight / 2 + metrics.getDescent()
Graphics2D graphics = image.createGraphics();
graphics.setColor(color);
Font font = new Font("SimHei",Font.BOLD,16);
FontDesignMetrics metrics = FontDesignMetrics.getMetrics(font);
int strHeight = metrics.getHeight();
graphics.setFont(font);
graphics.drawString("字符串", 100,100 + strHeight / 2 + metrics.getDescent() ); });
graphics.dispose();