Java의 그래픽 또는 그래픽 2D 클래스를 사용하면 문자열을 어떻게 페인트합니까?
-
05-07-2019 - |
문제
나는있다 String
그리고 나는 그것을 이미지에 페인트하고 싶다. 그러나 읽은 후에도 포인트를 칠하고 선을 그리울 수 있습니다. 2D 그래픽 튜토리얼의 텍스트 부분, 나는 내가 어떻게 받아 들일 수 있는지 알아낼 수 없다 String
내 그림에 페인트하십시오.
내가 잘못된 튜토리얼을 보지 않는 한 Graphics
또는 Graphics2D
), 나는 여전히 그루터기가있다.
해결책
다음 방법을 확인하십시오.
g.drawString();
그만큼 drawString()
방법은 필요한 것을 수행합니다.
예제 사용 :
protected void paintComponent(Graphics g){
g.setColor(Color.BLACK);
g.drawString(5, 40, "Hello World!");
}
좌표는 왼쪽 하단에 관한 것입니다. String
당신은 그리고 있습니다.
다른 팁
당신이 함께 놀고 싶다면 모양 끈의 (예 : 채우기 : 빨간색과 스트로크 : 파란색) :
Graphics2D yourGraphicsContext=(...);
Font f= new Font("Dialog",Font.PLAIN,14);
FontRenderContext frc = yourGraphicsContext.getFontRenderContext();
TextLayout tl = new TextLayout(e.getTextContent(), f, frc);
Shape shape= tl.getOutline(null);
//here, you can move your shape with AffineTransform (...)
yourGraphicsContext.setColor(Color.RED);
yourGraphicsContext.fill(shape);
yourGraphicsContext.setColor(Color.BLUE);
yourGraphicsContext.draw(shape);
제휴하지 않습니다 StackOverflow