C#/WPF 梯形图像转换
我有一个图像,我想在 WPF 中将其缩放/拉伸到梯形上。有简单的方法吗?我想实现3D效果/透视/弯曲。基本上拍摄 2D 图像并在 3D 空间中弯曲它。
这就是我想要完成的任务:
original: new:
* * * *
* * * *
另一个注意事项,我需要这一切很快发生。我尝试使用此代码,但性能无法使用: http://www.vcskicks.com/image -畸变.php
任何帮助将不胜感激。预先非常感谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为快速做到这一点的最简单方法是使用 WPF 3 D。只需设置一个带有透视投影的视口,然后将要转换内容的四边形放在那里,GPU 将完成剩下的工作。
WPF 有一个非常好的 MatrixTransform 类提供 GPU 加速转换几乎任何东西(及其衍生物,简化了例如旋转变换的应用)。遗憾的是,梯形变换不可能用简单的矩阵变换来完成,这些变换在数学上仅限于缩放、剪切和旋转(及其组合)。
编辑:您还可以在此处看到一些示例,3D 在WPF。
编辑2:
这里是显示透视图中显示的通用按钮的代码。不要尝试与它交互,如果你想要的话,谷歌“WPF Interactive3D”。
如果您只想在 3D 视图中显示图像,则不必使用 VisualBrush。
此外,如果您确实希望映射的内容适合视口的边缘,则必须固定坐标,您可能需要进行大量实验或一些数学来计算坐标。如果您得到一些不错的结果,请发布结果(清理代码后,我刚刚编辑了我在某处找到的示例)。
现在你正式欠我你的灵魂了:D
I think the easiest way to do this fast is using the WPF 3D. Just set-up a viewport with perspective projection and put a quad with the content being transformed there, GPU will do the rest.
WPF has a very nice MatrixTransform class which offers GPU-accelerated transformations of pretty much anything (and its derivatives which simplify application of for example rotation transformation). Sadly, the trapezoid transformation is not possible to do with simple matrix transform, these are mathematically limited to scaling, shearing and rotations (and their combinations).
EDIT: You can also see some examples here, 3D is really trivial in WPF.
EDIT 2:
here is code which displays a common button displayed in perspective view. Don't try to interact with it, google "WPF Interactive3D" if you want that.
If you want only image to be displayed in the 3D view, you don't have to use the VisualBrush.
Also, the coordinates will have to be fixed if you really want the mapped content to fit with the edges of the viewport, you will likely have to do a lot of experimenting or some math to calculate the coordinates. lease post the result if you get something nice (after you cleanup the code, I just edited an example I found somewhere).
And you now officially owe me your soul :D