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.
我的应用程序中有一个Image对象,用户可以拖动它。对象显示部分透明的图像,因此可以通过它看到窗口背景(本身就是位图)。
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.
我想为这个对象添加图形效果。假设我已经有了这种效果的算法 - 这不是问题。问题是如何将此算法转换为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.
所以我试着看看DropShadowEffect是如何工作的,但是Reflector中显示的实现是空的。我还试着看看我应该覆盖的抽象类Effect和ShaderEffect中的哪些方法,并且似乎没有与实际渲染效果相关的任何内容。
So how do I create my own effect?
那么我该如何创建自己的效果呢?
2 个解决方案
#1
3
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 :-)
最好和最快的方法是使用像素着色器(我认为从WPF 3.5 SP1开始支持)。它需要一些着色器语言(HLSL)知识,但是:-)
Here is a tutorial: How Do I: Create Custom Pixel Shader Effects for WPF
这是一个教程:如何:为WPF创建自定义像素着色器效果
a library on codeplex: Windows Presentation Foundation Pixel Shader Effects Library
Codeplex上的一个库:Windows Presentation Foundation像素着色器效果库
an article with .NET 4 information (including Sliverlight support which has it too): SilverShader – Introduction to Silverlight and WPF Pixel Shaders
一篇包含.NET 4信息的文章(包括也支持Sliverlight):SilverShader - Silverlight和WPF像素着色器简介
#2
1
A very cool tool (and resource) is Shazzam it will help you to create the effects and it contains a nice tutorial.
一个非常酷的工具(和资源)是Shazzam它将帮助您创建效果,它包含一个很好的教程。
#1
3
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 :-)
最好和最快的方法是使用像素着色器(我认为从WPF 3.5 SP1开始支持)。它需要一些着色器语言(HLSL)知识,但是:-)
Here is a tutorial: How Do I: Create Custom Pixel Shader Effects for WPF
这是一个教程:如何:为WPF创建自定义像素着色器效果
a library on codeplex: Windows Presentation Foundation Pixel Shader Effects Library
Codeplex上的一个库:Windows Presentation Foundation像素着色器效果库
an article with .NET 4 information (including Sliverlight support which has it too): SilverShader – Introduction to Silverlight and WPF Pixel Shaders
一篇包含.NET 4信息的文章(包括也支持Sliverlight):SilverShader - Silverlight和WPF像素着色器简介
#2
1
A very cool tool (and resource) is Shazzam it will help you to create the effects and it contains a nice tutorial.
一个非常酷的工具(和资源)是Shazzam它将帮助您创建效果,它包含一个很好的教程。