在java中绘制带有轮廓的文本 [英] Drawing text with outline in java

查看:26
本文介绍了在java中绘制带有轮廓的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working with graphcis2d in Java and am currently using this to draw text into a 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);

我想用不同颜色的轮廓绘制此文本.

I want to draw this text with an different color outline.

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 会颠倒顺序,并且不会使字母相互流动.

The problem with using this method, which works, is that I am working with arabic characters and using GlyphVector reverses the order and doesn't make the letters flow with one another.

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

Can someone please explain to me how to render arabic text in one color and have an outline with another?

这是我将使用的文本示例:嘭嘭嘭嘭

Heres a sample of the text I would be using: الرحمن

推荐答案

尝试使用

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

而不是 createGlyphVector

这篇关于在java中绘制带有轮廓的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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