绘制旋转对象时是否有确定的方法来确定笔对象的溢出? .Net GDI+
举个例子,假设您有一个矩形时钟。手由带有边框的填充三角形组成。边框是用 gdi+ 笔绘制的,粗细可以从 1 向上变化。
问题是,指针应该始终位于钟面的范围内。使用钢笔 Alignment.Inset 可以解决这个问题,但是,因为它的渲染效果很糟糕,所以它不是一个选项。
为了确保指针位于时钟的范围内,我根据角度找到边界上的交点。然后,我将手底部的 2 个点旋转相同的角度,并将这些点连接起来形成一个三角形。
现在,这可确保该点位于基于 1 像素线的边界上,但当使用较粗的线渲染时,它会超出边缘。为了解决这个问题,我做了一些基本的三角函数来根据笔的粗细来预测渲染后线条的长度,然后在找到交点之前减少时钟边界范围。
这有帮助,但不够准确。我一定遗漏了一些关于如何根据画笔粗细在 gdi+ 中准确渲染边框的信息。如果有人有任何知识,请告诉我。如果有人认为尝试解释它是浪费时间,那么请再次告诉我,这样可以节省我一天的时间。
ETA:下面是一个示例屏幕截图,它以大于 1 的笔宽度渲染手。忽略圆圈,并想象两条线延伸以在圆圈中心形成一个三角形。我需要一种方法来根据笔的大小、角度和时钟的大小来预测延伸到边界之外的部分的长度,以便我可以首先减小手的大小。
As an example imagine you have a rectangular clock. The hand is made of a filled triangle with a border. The border is drawn with a gdi+ pen and the thickness can vary from 1 upwards.
The problem is, the hand should always be within the bounds of the clock face. Using pen Alignment.Inset solves this problem but, because it renders terribly, it's not an option.
To ensure the hand is within the bounds of the clock, I find the intersection point on the border based on the angle. I then rotate the 2 points at the base of the hand by the same angle and join the points up to form a triangle.
Now, this ensures the point is on the border based on a 1 pixel line, but when rendered with a thicker line, it bleeds over the edge. To account for this, I did some basic trig to predict how long the line would be after rendering, based on the pen thickness, and then reduced the clock border bounds before finding the intersection point.
This helped, but was not accurate enough. I must be missing something about how exactly borders are rendered in gdi+ based on the pen thickness. If anyone has any knowledge then please let me know. If anyone thinks its a waste of time to even attempt to account for it then, again, let me know and save me a day.
ETA: Below is an example screenshot that renders the hand for a pen width larger that 1. Ignore the circle, and imagine the two lines extend to form a triangle at the centre of the circle. I need a way to predict the length of the part that extends beyond the border, based on the pen size, angle and clock size, so that I can reduce the hand size first.
alt text http://www.freeimagehosting.net/uploads/d3b5afb064.jpg
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论