填充两个 CubicCurve2D.Float 和一条线内的区域

发布于 2024-09-17 12:19:44 字数 580 浏览 9 评论 0原文

我正在用户界面中绘制一个选项卡。我已经有了我想要的轮廓。我该如何填充该区域?

这是绘制选项卡边框的代码:

val g2 = g.asInstanceOf[Graphics2D]

g2.translate(x, y)
val q = new CubicCurve2D.Float
q.setCurve(0, h, 8, h, 6, 0, 16, 0)
g2.setColor(Color.RED)
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON)
g2.draw(q)
val end = w - 8
g2.drawLine(17, 0, end, 0)
q.setCurve(end, 0, end+10, 0, w, h, w + 8, h)
g2.draw(q)

这是它绘制的线(红色线): image

我希望能够填充红线的内部。

I'm drawing a tab in a user interface. I have the outline as I want it. How do I fill the area?

This is the code that draws the border of the tab:

val g2 = g.asInstanceOf[Graphics2D]

g2.translate(x, y)
val q = new CubicCurve2D.Float
q.setCurve(0, h, 8, h, 6, 0, 16, 0)
g2.setColor(Color.RED)
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                    RenderingHints.VALUE_ANTIALIAS_ON)
g2.draw(q)
val end = w - 8
g2.drawLine(17, 0, end, 0)
q.setCurve(end, 0, end+10, 0, w, h, w + 8, h)
g2.draw(q)

and this is the line it draws (the red one): image

I would like to be able to fill the inside of the red line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

久随 2024-09-24 12:19:52

我不知道Scala,但在Java 2D中,Graphics2D对象可以填充或绘制任何形状 对象。对于某些任意形状,您可以使用 GeneralPath 对象,如:

GeneralPath path = new GeneralPath();
path.lineTo(10, 10);
path.lineTo(0, 10);
path.lineTo(0, 0);
graphics.setColor(Color.RED);
graphics.fill(path);

GeneralPath 对象还具有绘制贝塞尔曲线和四边形的方法,因此您可以绘制路径,然后选择填充或绘制其轮廓。

添加了新链接到 GeneralPath

I don't know Scala, but in Java 2D, the Graphics2D object can fill or draw the outline of any Shape object. For some arbitrary shape you would define it with GeneralPath object, such as:

GeneralPath path = new GeneralPath();
path.lineTo(10, 10);
path.lineTo(0, 10);
path.lineTo(0, 0);
graphics.setColor(Color.RED);
graphics.fill(path);

The GeneralPath object also has methods for drawing bezier curves and quads, so you would draw the path and then choose to fill or draw the outline of it.

Added new link to GeneralPath

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文