创建一个从Java中字体对象Shape对象 [英] Create a Shape Object from Font Object in Java

查看:406
本文介绍了创建一个从Java中字体对象Shape对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字体对象和一个字符串。我想返回一个Shape对象,它是字符串的重新presentation。我有一大堆其他类将显示String和照顾它的。

I have a font object and a String. I want to return a Shape Object that is a representation of the String. I have a whole bunch of other classes that will display the String and take care of it.

我有麻烦搞清楚如何做到这一点时,我的的有一个图形/ Graphics2D对象。任何帮助吗?我已经搜查了网,但很难找到有用的链接。

I'm having trouble figuring out how to do this when I do not have a graphics/graphics2d object. Any Help? I have searched the net but had trouble finding helpful links.

public class SpecializationOfTester extends ParentTester {

    private String      str;
    private Font        font;


    public SpecializationOfTester(String str, Font font) {
        this.font = font;
        this.str = str;
    }

    public Shape getShape()
    {
        Shape           s;
        //
        //
        return s;
    }

}

感谢

推荐答案

您可以使用的 的GlyphVector#getOutline() ,提到的此处。您可以创建一个的BufferedImage ,为的 在Java SE平台<使用无头模式/ em>的

You can use GlyphVector#getOutline(), as mentioned here. You can create a graphics context in a BufferedImage, as discussed in Using Headless Mode in the Java SE Platform.

又见这些吸引人的例子:

See also these appealing examples:

测试 ,由于的 SAVVAS Dalkitsis

这篇关于创建一个从Java中字体对象Shape对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆