WPF - 命中测试字符的渲染像素
有没有办法测试wpf中字符的像素?我希望能够命中字符“i”的点,但当我单击点和“i”行之间的空格时却得不到命中。我尝试使用 DrawingContext.DrawText 方法来执行此操作,但是当我使用 VisualTreeHelper.HitTest 方法对包含文本的生成的 DrawingVisual 进行测试时,它不会区分字符的空间和黑色像素。它为角色边界框中的每个点提供命中。有办法做到这一点吗?
Is there a way to hit test the pixels of characters in wpf? I want to be able to get a hit for the dot of the character 'i' but don't get a hit when I click the space between the dot and the line of 'i'. I tried to do it using DrawingContext.DrawText method and but when I hit test against the resulting DrawingVisual, which contains the text, using VisualTreeHelper.HitTest method it doesn't differentiate the space and the black pixels of the character. It gives a hit for every point in the bounding box of a character. Is there a way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案。为此,您必须转到较低级别的 GlyphRunDrawing。使用此处的代码并替换 GeometryDrawing使用 GlyphRunDrawing。然后获取 GeometryGroup,其中包含每个字符作为 Geometry,并使用代码进行命中测试:
I found the solution. To do this you have to go to lower level to GlyphRunDrawing. Use the code here and substitute GeometryDrawing with GlyphRunDrawing. Then get the GeometryGroup, which contains each character as Geometry, and do the hit testing with the code: