我想教我的孩子写数字,所以我想到画可追踪的字母到
Graphics2D
我尝试过以下方法
float[] textDash = {15.0f};
g2d.setFont(g2d.getFont().deriveFont(400f));
metrics = g2d.getFontMetrics(g2d.getFont());
String numberString = "3";
BasicStroke dashedStroke = new BasicStroke(5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, textDash, 0.0f);
FontRenderContext frc = g2d.getFontRenderContext();
GlyphVector gv = g2d.getFont().createGlyphVector(frc, numberString);
Shape numberStringOutline = gv.getOutline();
AffineTransform at = AffineTransform.getTranslateInstance(30, 200);
numberStringOutline = at.createTransformedShape(numberStringOutline);
numberStringOutline = dashedStroke.createStrokedShape(numberStringOutline);
g2d.fill(numberStringOutline);
我正在尝试画一条实线来追踪数字 3,就像在描图纸中看到的那样,而不是像您看到的轮廓。
关于如何修改它以便我获得完整的数字而不是轮廓有什么建议吗?