Java:填充形状的线条
这并不是很重要,但它困扰了我一段时间。
问题描述:
给定:一条线(Line2D)
想要:将线绘制为楔形(填充通用路径)
当然,这可以通过将楔形创建为通用路径然后用图形填充它来完成(我的解决方案)。
我的第一种方法是楔形描边线,因为出于某种原因我不想更改线对象,而且我只是想绘制线对象而不再考虑它。 创建楔形笔划没有问题(进行一些计算,然后创建通用路径) - 但我无法(轻松)填充它
显然,Graphics2D 的填充似乎只填充了它得到的形状- 并且不处理笔画的填充(如果仔细想想,这种行为是有道理的)。
问题:有什么方法可以填充 Stroke 的形状(填充形状 - 更具体地说:GeneralPath - 在绘制之前以某种方式填充)?
This is not really important, but it was bothering me for a little while.
Problem description:
Given: a line (Line2D)
Wanted: drawing the line as a wedge (Filled GeneralPath)
Surely this can be done by creating the wedge as General Path and then filling it by the Graphics (my solution).
My first approach would have been a wedge-stroked line, because I didn't want to change the line object for some reason, also I just wanted to draw the line object and not think about it any more.
Creating the wedge-stroke was no problem (Some calculations and then creating the General Path) - but I was not able to fill it (easily)
Apparently it seems the fill of Graphics2D only fills the shape it gets - and does not handle the filling of the stroke (that behavior makes sense if one thinks about it).
Question: Is there any way to fill a shape of a Stroke (filling a shape - more specifically: a GeneralPath - somehow before drawing it)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您将 Line2D 传递到那里,
BasicStroke.public Shape createStrokedShape(Shape s)
可能会有所帮助吗?May be
BasicStroke.public Shape createStrokedShape(Shape s)
can help if you pass the Line2D there?使用
createStrokedShape()
后,请注意draw()
“描画Shape
的轮廓”,而fill()
“填充Shape
的内部。”Once you use
createStrokedShape()
, note thatdraw()
"strokes the outline of aShape
," whilefill()
"fills the interior of aShape
."您还可以指定
BasicStroke
的cap
和join
参数You may also specify
cap
andjoin
parameters ofBasicStroke