Getting the Shape from the Outline of Text - Java 2D Graphics

Java examples for 2D Graphics:Text

Description

Getting the Shape from the Outline of Text

Demo Code

import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.font.FontRenderContext;
import java.awt.font.TextLayout;

public class Main {
  Shape getTextShape(Graphics2D g2d, String str, Font font) {
    FontRenderContext frc = g2d.getFontRenderContext();
    TextLayout tl = new TextLayout(str, font, frc);
    return tl.getOutline(null);
  }// ww  w .j a  va2  s  .c om
}

Related Tutorials