我正在使用PixelShader效果。
- 用于调整对比度、亮度、CMY的图像效果;RGB使用
SLIDERS
- 混合模式预定义的图像效果&在组合框中加载,用户可以选择自己的选择。
这是Image元素和图像效果,用于调整对比度,亮度,CMY &RGB以这种方式应用。
<Viewbox x:Name="cImage" Stretch="Uniform" Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" Margin="0" >
<Image x:Name="ViewedPhoto" Source="IMG_0071.jpg"
Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,5,0,95" >
<Image.Effect>
<l:BrightContrastEffect
Brightness="{Binding Value, ElementName=bVal}"
Contrast="{Binding Value, ElementName=cVal}"
Red="{Binding Value, ElementName=rVal}"
Green="{Binding Value, ElementName=gVal}"
Blue="{Binding Value, ElementName=blVal}"
/>
</Image.Effect>
</Image>
</Viewbox>
亮度滑块:
<Slider Maximum="1" Minimum="-1" x:Name="bVal" TickFrequency="1" TickPlacement="BottomRight" />
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Value, ElementName=bVal, UpdateSourceTrigger=PropertyChanged}" TextAlignment="Right" Width="30" Height="10" Margin="0" RenderTransformOrigin="-1.167,0.423" Visibility="Hidden"/>
</StackPanel>
当我移动滑块来调整对比度,亮度,CMY &Rgb it's working
。
我使用comboBox应用预定义的混合模式图像效果。
<ComboBox x:Name="cColorEffects" SelectionChanged="cColorEffects_SelectionChanged" />
为了显示不同的效果,我首先调用ViewedPhoto.Effect = null;
&然后应用选定的效果。
if (cColorEffects.SelectedIndex == 0)
{
ViewedPhoto.Effect = null;
ViewedPhoto.Effect = new AverageEffect();
}
if (cColorEffects.SelectedIndex == 1)
{
ViewedPhoto.Effect = null;
ViewedPhoto.Effect = new ColorBurnEffect();
}
问题:
我通过comboBox调用另一个图像效果,因此图像效果用于调整对比度,亮度,CMY &
我使用
ViewedPhoto.Effect = null;
图像效果来调整对比度,亮度,CMY &;RGB不工作。
我想让the sliders working for adjusting
对比度,亮度,CMY &RGB和apply the blend mode image effects simultaneously
。我怎样才能解决这个问题?还是给我个解决办法?
我一直在想我可以让滑块按语法绑定和图像效果。这有意义吗?如果它是好的;我怎么应用这个呢?
<Image x:Name="ViewedPhoto" >
<Image.Effect>
<l:BrightContrastEffect
Brightness="{Binding Value, ElementName=bVal}"
Contrast="{Binding Value, ElementName=cVal}"
Red="{Binding Value, ElementName=rVal}"
Green="{Binding Value, ElementName=gVal}"
Blue="{Binding Value, ElementName=blVal}"
/>
</Image.Effect>
</Image>
<Slider Maximum="1" Minimum="-1" x:Name="bVal" TickFrequency="1" TickPlacement="BottomRight" />
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Value, ElementName=bVal, UpdateSourceTrigger=PropertyChanged}" Visibility="Hidden"/>
<Button x:Name="bReset" Content="R" Height="10" Width="30" Margin="35,0,0,0" Click="bReset_Click"/>
</StackPanel>
<Slider Maximum="1" Minimum="-1" x:Name="cVal" TickFrequency="1" TickPlacement="BottomRight" />
<StackPanel Orientation="Horizontal">
<TextBox Text="{Binding Value, ElementName=cVal, UpdateSourceTrigger=PropertyChanged}" Visibility="Hidden" />
<Button x:Name="cReset" Content="R" Height="10" Width="30" Margin="35,0,0,0" Click="cReset_Click"/>
</StackPanel>
附加信息与代码:
public class BlendModeEffect : ShaderEffect
{
public BlendModeEffect()
{
UpdateShaderValue(InputProperty);
UpdateShaderValue(TextureProperty);
}
public Brush Input
{
get { return (Brush)GetValue(InputProperty); }
set { SetValue(InputProperty, value); }
}
public static readonly DependencyProperty InputProperty =
ShaderEffect.RegisterPixelShaderSamplerProperty
(
"Input",
typeof(BlendModeEffect),
0
);
public Brush Texture
{
get { return (Brush)GetValue(TextureProperty); }
set { SetValue(TextureProperty, value); }
}
public static readonly DependencyProperty TextureProperty =
ShaderEffect.RegisterPixelShaderSamplerProperty
(
"Texture",
typeof(BlendModeEffect),
1
);
}
//Contrast, Brightness, CMY & RGB Effect
public class BrightContrastEffect : ShaderEffect
{
private static PixelShader m_shader =
new PixelShader() { UriSource = MakePackUri("bricon.ps") };
public BrightContrastEffect()
{
PixelShader = m_shader;
UpdateShaderValue(InputProperty);
UpdateShaderValue(BrightnessProperty);
UpdateShaderValue(ContrastProperty);
UpdateShaderValue(RedProperty);
UpdateShaderValue(GreenProperty);
UpdateShaderValue(BlueProperty);
}
// MakePackUri is a utility method for computing a pack uri
// for the given resource.
public static Uri MakePackUri(string relativeFile)
{
Assembly a = typeof(BrightContrastEffect).Assembly;
// Extract the short name.
string assemblyShortName = a.ToString().Split(',')[0];
string uriString = "pack://application:,,,/" +
assemblyShortName +
";component/" +
relativeFile;
return new Uri(uriString);
}
public Brush Input
{
get { return (Brush)GetValue(InputProperty); }
set { SetValue(InputProperty, value); }
}
public static readonly DependencyProperty InputProperty = ShaderEffect.RegisterPixelShaderSamplerProperty("Input", typeof(BrightContrastEffect), 0);
public float Brightness
{
get { return (float)GetValue(BrightnessProperty); }
set { SetValue(BrightnessProperty, value); }
}
public static readonly DependencyProperty BrightnessProperty = DependencyProperty.Register("Brightness", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(0)));
public float Contrast
{
get { return (float)GetValue(ContrastProperty); }
set { SetValue(ContrastProperty, value); }
}
public static readonly DependencyProperty ContrastProperty = DependencyProperty.Register("Contrast", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(1)));
public float Red
{
get { return (float)GetValue(RedProperty); }
set { SetValue(RedProperty, value); }
}
public static readonly DependencyProperty RedProperty = DependencyProperty.Register("Red", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(2)));
public float Green
{
get { return (float)GetValue(GreenProperty); }
set { SetValue(RedProperty, value); }
}
public static readonly DependencyProperty GreenProperty = DependencyProperty.Register("Green", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(3)));
public float Blue
{
get { return (float)GetValue(BlueProperty); }
set { SetValue(BlueProperty, value); }
}
public static readonly DependencyProperty BlueProperty = DependencyProperty.Register("Blue", typeof(double), typeof(BrightContrastEffect), new UIPropertyMetadata(0.0, PixelShaderConstantCallback(4)));
//private static PixelShader m_shader = new PixelShader() { UriSource = new Uri(@"pack://application:,,,/CustomPixelRender;component/bricon.ps") };
}
//Average Blend Mode Effect
public class AverageEffect : BlendModeEffect
{
public static Uri MakePackUri(string relativeFile)
{
Assembly a = typeof(ColorBurnEffect).Assembly;
// Extract the short name.
string assemblyShortName = a.ToString().Split(',')[0];
string uriString = "pack://application:,,,/" +
assemblyShortName +
";component/" +
relativeFile;
return new Uri(uriString);
}
static AverageEffect()
{
_pixelShader.UriSource = MakePackUri("AverageEffect.ps");
}
public AverageEffect()
{
this.PixelShader = _pixelShader;
}
private static PixelShader _pixelShader = new PixelShader();
}
//ColorBurn Effect
public class ColorDodgeEffect : BlendModeEffect
{
public static Uri MakePackUri(string relativeFile)
{
Assembly a = typeof(ColorBurnEffect).Assembly;
// Extract the short name.
string assemblyShortName = a.ToString().Split(',')[0];
string uriString = "pack://application:,,,/" +
assemblyShortName +
";component/" +
relativeFile;
return new Uri(uriString);
}
static ColorDodgeEffect()
{
_pixelShader.UriSource = MakePackUri("ColorDodgeEffect.ps");
}
public ColorDodgeEffect()
{
this.PixelShader = _pixelShader;
}
private static PixelShader _pixelShader = new PixelShader();
}
//BlendModeEffect
public class BlendModeEffect : ShaderEffect
{
public BlendModeEffect()
{
UpdateShaderValue(InputProperty);
UpdateShaderValue(TextureProperty);
}
public Brush Input
{
get { return (Brush)GetValue(InputProperty); }
set { SetValue(InputProperty, value); }
}
public static readonly DependencyProperty InputProperty =
ShaderEffect.RegisterPixelShaderSamplerProperty
(
"Input",
typeof(BlendModeEffect),
0
);
public Brush Texture
{
get { return (Brush)GetValue(TextureProperty); }
set { SetValue(TextureProperty, value); }
}
public static readonly DependencyProperty TextureProperty =
ShaderEffect.RegisterPixelShaderSamplerProperty
(
"Texture",
typeof(BlendModeEffect),
1
);
}
根据SO聊天使用建议。我已经调用 brightcontrsteffect 作为滑动块更改事件处理程序中图像的新效果。我按程序语法设置投标值。
private void cVal_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
cColorEffects.SelectedIndex = 0;
BrightContrastEffect bce = new BrightContrastEffect();
BindingOperations.SetBinding(bce, BrightContrastEffect.ContrastProperty, new Binding("Value") { Source = cVal });
ViewedPhoto.Effect = bce;
}
我对其他滑块应用了相同的方法。