5

我正在使用 Java 中的 graphcis2d,目前正在使用它来将文本绘制到 bufferedImage

Font font1 = new Font("Arial", Font.PLAIN, 120);
g2d.setFont(font1);
FontMetrics fm1 = g2d.getFontMetrics(font1);     
g2d.drawString(s[1], width/2-fm1.stringWidth(s[1])/2, height/4-70);

我想用不同的颜色轮廓绘制这个文本。

GlyphVector gv = font1.createGlyphVector(g2d.getFontRenderContext(), s[1]);
Shape shape = gv.getOutline();
g2d.setStroke(new BasicStroke(4.0f));
g2d.translate(width/2-fm1.stringWidth(s[1])/2, height/4-70);
g2d.draw(shape);        

使用这种有效的方法的问题在于,我正在处理阿拉伯字符,而使用 GlyphVector 会颠倒顺序并且不会使字母彼此流动。

有人可以向我解释如何以一种颜色呈现阿拉伯文字并与另一种颜色有轮廓吗?

这是我将使用的文本示例:الرحمن

4

3 回答 3

2

尝试使用

layoutGlyphVector(FontRenderContext frc, char[] text, int start, int limit, int flags) 

而不是createGlyphVector

于 2011-09-19T08:20:44.423 回答
2

You may be able to use the method createStrokedShape() on the glyph's Shape returned by getOutline(). See also CompositeStroke, demonstrated here.

于 2011-09-19T03:19:09.120 回答
1

一个技巧是用轮廓颜色多次绘制文本,通过轮廓宽度在 +/- x 和 +/- y 方向上改变位置,然后在标称位置绘制前景色。它并不完美,但如果轮廓相对于字母的笔划宽度不太厚,它看起来会非常好。

于 2011-09-19T02:10:07.630 回答