问题描述
我想重新在WPF锥形/圆形渐变。我看着继承System.Windows.Media.GradientBrush - 这可以从继承 - 但使用了大量的内部管道来完成这项工作(从System.Windows.Media.Brush继承。)
I would like to recreate a conical/circular gradient in WPF. I've looked into inheriting System.Windows.Media.GradientBrush - which can be inherited from - but uses a lot of internal plumbing to get the job done (inherited from System.Windows.Media.Brush)
这是如何实现这一目标的任何想法,将不胜感激(最好而不诉诸位图)
Any ideas on how to achieve this would be appreciated (preferrably without resorting to bitmaps)
干杯。
丹
这问题被问了一些时间早在7(的),但我不想一个复活老问题。
This question was asked some time back in July (http://stackoverflow.com/questions/1187597/circular-gradient-and-wpf) but I didn't want to resurrect an old question.
推荐答案
您可以创建自定义效果。我会建议下载你还需要的DirectX SDK。 ,给该元素则水平梯度申请将其改造成一个锥形渐变的效果。
You could create a custom Effect. I would recommend downloading Shazzam you will also need the DirectX SDK. Give the element a horizontal gradient then apply the effect to transform it into a cone gradient.
/// <class>AngleGradient</class>
/// <description>Renders an angle gradient.</description>
//-----------------------------------------------------------------------------------------
// Shader constant register mappings (scalars - float, double, Point, Color, Point3D, etc.)
//-----------------------------------------------------------------------------------------
/// <summary>The centre of the gradient.</summary>
/// <minValue>0</minValue>
/// <maxValue>1</maxValue>
/// <defaultValue>0.5,0.5</defaultValue>
float2 Centre : register(C0);
/// <summary>The start angle.</summary>
/// <minValue>0</minValue>
/// <maxValue>1</maxValue>
/// <defaultValue>0</defaultValue>
float Angle : register(C1);
//--------------------------------------------------------------------------------------
// Sampler Inputs (Brushes, including ImplicitInput)
//--------------------------------------------------------------------------------------
sampler1D implicitInputSampler : register(S0);
static const float PI = 3.14159265f;
//--------------------------------------------------------------------------------------
// Pixel Shader
//--------------------------------------------------------------------------------------
float4 main(float2 uv : TEXCOORD) : COLOR
{
float angle = atan2(uv.y-Centre.y, uv.x-Centre.x)+PI;
angle = (angle/(2*PI)) + Angle;
return tex1D(implicitInputSampler,min(angle > 1 ? angle-1 : angle,0.99));
这篇关于如何实现在WPF锥形/锥/圆形渐变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!