在 WPF 画布上的鼠标按下点处添加形状

发布于 2024-12-21 09:25:08 字数 187 浏览 3 评论 0原文

我有一个带有缩放功能的画布(ScaleTransform)。现在我已经按某个任意缩放值缩放了画布。我在每个 MouseDown 事件的 MouseDown 点添加 RectangleGeomtry。但奇怪的是,形状被添加到画布上,并带有一些 +/-dx 和 +/-dy 到 MouseDown 点。

非常感谢任何关于为什么会发生这种情况的线索。

I have a canvas with zoom (ScaleTransform). Now I have scaled the canvas by some arbitrary zoom value. I'm adding RectangleGeomtry at the MouseDown Point with every MouseDown event. But the strange thing is the Shape is getting added to the canvas with some +/-dx and +/-dy to the MouseDown Point.

Any leads on why this happening is much appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

空城缀染半城烟沙 2024-12-28 09:25:08

在缩放画布中,您应该获得点的逆变换(缩放和平移),然后在构造几何图形后应用变换(缩放和平移)。它起作用了。我不确定这是否是最好的方法。

In a scaled canvas, you should get an inverse transform (Scale and Translate) of the point and then apply transform (Scale and Translate) after constructing geometry. It worked. I am not sure if that's the best way.

活雷疯 2024-12-28 09:25:08

当您应用比例变换时,所有点都会发生变换(移动)。例如,如果您有点 A(10,20),并且您对图像应用比例 2,则点 A 现在将是 A(20,40)。当您想向缩放图像添加一个点时,您必须像这样调整坐标......(乘以比例)

When you apply a scale transform all points get transformed (moved). For instance if you have point A(10,20) and you apply a scale of 2 to the image your point A will now be A(20,40). When you want to add a point to a scaled image you must adjust the coordinates like that ... (multiply by scale)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文