주어진 텍스트로 jpg/png를 렌더링하는 서블릿을 작성하고 있습니다. 텍스트를 렌더링 된 이미지의 가운데에 배치하고 싶습니다. 나는 폭을 얻을 수 있지만, 내가지고있어 높이가 잘못된 것 같다java.awt.BufferdImage/Graphics2D의 텍스트의 높이를 올바르게 취득 할 수 없다
Font myfont = new Font(Font.SANS_SERIF, Font.BOLD, 400);
BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_ARGB);
Graphics2D g = image.createGraphics();
g.setFont(myfont);
g.setColor(Color.BLACK);
FontMetrics fm = g.getFontMetrics();
Integer textwidth = fm.stringWidth(imagetext);
Integer textheight = fm.getHeight();
FontRenderContext fr = g.getFontRenderContext();
LineMetrics lm = myfont.getLineMetrics("5", fr);
float ascent = lm.getAscent();
float descent = lm.getDescent();
float height = lm.getHeight();
g.drawString("5", ((imagewidth - textwidth)/2) , y?);
g.dispose();
ImageIO.write(image, "png", outputstream);
이 내가 얻는 값은 다음과 같습니다 textwidth = 222 되는 textHeight = 504 = 87 높이 상승 = 402 하강 = 503
"5"라는 정확한 높이를 얻는 방법을 아는 사람이 있습니까? 예상 높이 그것은 조금 여전히 꺼져
해결했습니다. – Tommy