填充两个 CubicCurve2D.Float 和一条线内的区域
我正在用户界面中绘制一个选项卡。我已经有了我想要的轮廓。我该如何填充该区域?
这是绘制选项卡边框的代码:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不知道Scala,但在Java 2D中,Graphics2D对象可以填充或绘制任何形状 对象。对于某些任意形状,您可以使用 GeneralPath 对象,如:
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:
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