WPF/Silverlight 如何计算控件中的总立方单位/像素?
我的 silverlight 应用程序中有一个 scribbale inkpresenter,我在不同的形状中多次使用它,我想计算 inkpresenter 被乱写的百分比,
我的问题是,由于 inkpresenter 的形状可以是圆形或多边形我不知道如何获得可涂鸦表面上可用的单位/像素。
据我了解,actualWidth和actualHeight属性只会通过计算帮助我计算矩形形状,
units = uielemnt.Actualwidth * uielement.ActualHeight
但对于服装形状,我不确定如何计算actualWidth/Height。
I have a scribbale inkpresenter in my silverlight app that I'm using multiple times in different shapes, I want to calculate how much percent of the inkpresenter has been scribbled,
My problem is that since the shape of the ink presenter can be circular or poly I don't know how i can get the units/pixels there is available on the scribbable surface.
As far as i understand is that the actualWidth and actualHeight properties will only help me for rectangular shape by calculating
units = uielemnt.Actualwidth * uielement.ActualHeight
but for costum shapes I'm not sure how the actualWidth/Height are calculated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
WPF 答案
在 WPF 中,您只需使用 Geometry.Combine 组合笔划几何图形,然后对组合几何图形调用 GetArea 即可获取覆盖的总面积。
Silverlight 答案
在 Silverlight 中,您没有 Geomerty.Combine 或 Geometry.GetArea,也没有 RenderTargetBitmap。所以在Silverlight中我认为你必须自己进行计算。
以下是设置步骤:
这是主循环:
这里是计算面积的内循环:
就是这样。
有关 Silverlight 答案的更多详细信息
将 PathGeometry 的段转换为三次贝塞尔近似值的公式:
计算活动贝塞尔曲线的交点:
WPF Answer
In WPF you can just use Geometry.Combine to combine the stroke geometries, then call GetArea on the combined geometry to get the total area covered.
Silverlight Answer
In Silverlight you don't have Geomerty.Combine or Geometry.GetArea, and you also don't have RenderTargetBitmap. So in Silverlight I think you have to do the calculations yourself.
Here are the setup steps:
Here is the main loop:
Here is the inner loop that computes the area:
That's it.
More details on Silverlight answer
Formulas to convert segments of a PathGeometry into a cubic bezier approximation:
Computing intersections of active Bezier curves: