let's see the definition: public Shape getOutline(AffineTransform tx) { GeneralPath dstShape = new GeneralPath(GeneralPath.WIND_NON_ZERO); ..... return dstShape; } In fact, you used GereralPath to do this assignment.
to wobelisk(): 受到你的启发我自己也实现了一个方法; public void paint(Graphics g) { Graphics2D g2 = (Graphics)g; Font font = g2.getFont(); FontRenderContext frc = g2.getFontRenderContext(); GlyphVector gv = font.create(frc, "学要空心处理的文字"); Shape outline = gv.getOutline(x, y); g2.draw(outline); }不知道这个方法在性能上会不会比你的好一些
public void paint(Graphics g){
Graphics2D g2=(Graphics2D) g;
Font font=new Font("FangSong",Font.PLAIN,90);
FontRenderContext frc = g2.getFontRenderContext();
TextLayout tl = new TextLayout("空心", font, frc);
Shape sh=tl.getOutline(null);
AffineTransform t= new AffineTransform();
t.setTransform(0.7,0,0,0.7,40,180);
sh=tl.getOutline(t);
g2.draw(sh);
...
可是考虑到效率,如果每输入一个字把它设为空心,不是每次都有new TextLayout了吗?
public Shape getOutline(AffineTransform tx) {
GeneralPath dstShape = new GeneralPath(GeneralPath.WIND_NON_ZERO);
.....
return dstShape;
}
In fact, you used GereralPath to do this assignment.
受到你的启发我自己也实现了一个方法;
public void paint(Graphics g)
{
Graphics2D g2 = (Graphics)g;
Font font = g2.getFont();
FontRenderContext frc = g2.getFontRenderContext();
GlyphVector gv = font.create(frc, "学要空心处理的文字");
Shape outline = gv.getOutline(x, y);
g2.draw(outline);
}不知道这个方法在性能上会不会比你的好一些
上面那句错的应该是GlyphVector gv = font.createGlyphVector(frc, "需要空心处理的文字");