如何在 WPF 中创建自己的图形效果?
我的应用程序中有一个 Image 对象,用户可以拖动它。该对象显示部分透明的图像,因此可以通过它看到窗口背景(本身就是位图)。
我想给这个对象添加图形效果。假设我已经有了实现这种效果的算法——这不是问题。问题是如何将此算法引入WPF。
所以我尝试看看 DropShadowEffect
是如何工作的,但是 Reflector 中显示的实现是空的。我还尝试查看应该重写抽象类 Effect
和 ShaderEffect
中的哪些方法,但似乎没有任何与实际渲染效果相关的内容。
那么如何创建自己的效果呢?
I have an Image
object in my application which the user can drag around. The object displays an image which is partly transparent, so the window background (which is itself a bitmap) can be seen through it.
I want to add a graphics effect to this object. Assume that I already have an algorithm for this effect — that’s not the issue. The issue is how to get this algorithm into WPF.
So I tried to look at how DropShadowEffect
works, but the implementation displayed in Reflector is empty. I also tried to look at what methods from the abstract classes Effect
and ShaderEffect
I should override and there doesn’t seem to be anything related to actually rendering an effect.
So how do I create my own effect?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最好、最快的方法是使用 像素着色器(我认为从 WPF 3.5 SP1 开始支持)。不过,它需要一些着色器语言(HLSL)知识:-)
这是一个教程:< a href="http://windowsclient.net/learn/video.aspx?v=296117" rel="nofollow">如何:为 WPF 创建自定义像素着色器效果
codeplex 上的一个库:Windows Presentation Foundation Pixel Shader Effects Library
一篇包含 .NET 4 信息的文章(包括 Sliverlight 支持,也有): SilverShader – Silverlight 和 WPF 像素着色器简介
The best and fastest way is to use pixel shaders (supported starting with WPF 3.5 SP1 I think) . It will require some shader language (HLSL) knowledge, though :-)
Here is a tutorial: How Do I: Create Custom Pixel Shader Effects for WPF
a library on codeplex: Windows Presentation Foundation Pixel Shader Effects Library
an article with .NET 4 information (including Sliverlight support which has it too): SilverShader – Introduction to Silverlight and WPF Pixel Shaders
Shazzam 是一个非常酷的工具(和资源),它将帮助您创建效果,并且包含一个很好的教程。
A very cool tool (and resource) is Shazzam it will help you to create the effects and it contains a nice tutorial.