2011-03-30 2 views
0

다른 사람이 내 구문을 확인할 수 있습니까? "Times New Roman", "Arial", "Verdana"를 fontName으로 전달하고 fontSize에 8,12,15 등을 사용하고 있습니다. 글꼴을 변경하지 않습니다. 나는 이미지 위에 텍스트를 쓰려고하고있다.Java에서 글꼴 및 도면 문자열을 변경하는 올바른 구문은 무엇입니까?

Graphics2D g2d = (Graphics2D) bufferedImage.getGraphics(); 
g2d.drawImage(photo, 0, 0, null); 
g2d.setColor(Color.white); 
Font font = new Font(fontName, Font.PLAIN, fontSize); 
g2d.setFont(font); 
g2d.drawString(text,x,y); 

답변

2

마침내 필자는 목록에있는 글꼴이 시스템에 없었기 때문에 getAllFonts() 메서드를 사용하고 목록에서 해당 글꼴 만 전달해야한다는 것을 알게되었습니다.

0

당신은 태양 문서에서이

BufferedImage img = new BufferedImage(
    w, h, BufferedImage.TYPE_INT_ARGB); 
Graphics2D g2d = img.createGraphics(); 
g2d.drawImage(photo, 0, 0, null); 
g2d.setPaint(Color.red); 
//example :  g2d.setFont(new Font("Serif", Font.BOLD, 15)); 
g2d.setFont(new Font(fontName, Font.BOLD, size)); 
String s = "Hello, world!"; 
// assuming x & y is set using graphic's font metrics 
g2d.drawString(s, x, y); 
g2d.dispose(); 

발췌

로 getGraphics

공공 그래픽로 getGraphics()를이 메소드는 Graphics2D를 돌려줍니다 만, 여기 입니다 일을해야 이전 버전과의 호환성을 위해. Graphics2D를 반환하도록 선언되었으므로 createGraphics가 더 편리합니다 ( ).

이것은 실제로 getGraphics API를 사용하면 안된다는 의미는 아닙니다. 위의 코드가 저에게 효과적이었습니다 :)