←Select platform

DesaturateEffect Class

Summary

Increase or decrease the image saturation based on the given parameter.

Syntax
C#
VB
C++
public class DesaturateEffect : ShaderEffect 
  
Public Class DesaturateEffect  
   Inherits System.Windows.Media.Effects.ShaderEffect 
   Implements System.Windows.Media.Animation.IAnimatable  
public ref class DesaturateEffect : public System.Windows.Media.Effects.ShaderEffect, System.Windows.Media.Animation.IAnimatable   

Remarks

Negative values decrease the saturation of colors. Positive values increase the saturation. The saturation level is increased or decreased by a percentage of its present saturation level. For example, an increase of 20 of the current saturation level "L" will raise the new saturation level "L1" to a value L + 0.20 * L. Likewise, increasing the saturation level 100 doubles the saturation level ( L1 = L + 1.0 * L). Decreasing the saturation level 100 will set the new saturation level to 0. This process is carried out for every pixel.

Example
C#
VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Windows.Controls; 
using Leadtools.Windows.Media; 
using Leadtools.Windows.Media.Effects; 
 
class DesaturateEffectExampleWindow : Window 
{ 
   public DesaturateEffectExampleWindow() 
   { 
      StackPanel sp = new StackPanel(); 
      Content = sp; 
 
      ImageViewer theViewer = new ImageViewer(); 
 
      theViewer.HorizontalAlignment = HorizontalAlignment.Center; 
      theViewer.VerticalAlignment = VerticalAlignment.Top; 
      theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left; 
      theViewer.ImageVerticalAlignment = VerticalAlignment.Top; 
 
      sp.Children.Add(theViewer); 
 
      // Create the sliders 
      TextBlock tb = new TextBlock(); 
      tb.HorizontalAlignment = HorizontalAlignment.Center; 
      tb.Text = "Saturation:"; 
      sp.Children.Add(tb); 
 
      Slider theSlider = new Slider(); 
      theSlider.Minimum = 0.0; 
      theSlider.Maximum = 1.0; 
      theSlider.Width = 400; 
      theSlider.Orientation = Orientation.Horizontal; 
      theSlider.IsSnapToTickEnabled = true; 
      theSlider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight; 
      theSlider.TickFrequency = 0.1; 
      theSlider.AutoToolTipPrecision = 2; 
      theSlider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight; 
 
      sp.Children.Add(theSlider); 
 
      // Load an image into the viewer 
      theViewer.Source = new BitmapImage(new Uri(System.IO.Path.Combine(LEAD_VARS.ImagesDir, "Cannon.jpg"))); 
 
      // Create the effect 
      DesaturateEffect effect = new DesaturateEffect(); 
      effect.Saturation = 0.5; 
      theViewer.ImageEffect = effect; 
 
      // Bind the properties 
      Binding bind = new Binding(); 
      bind.Source = effect; 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; 
      bind.Path = new PropertyPath("Saturation"); 
      theSlider.SetBinding(Slider.ValueProperty, bind); 
 
      Title = "Using DesaturateEffect"; 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.Windows.Controls 
Imports Leadtools.Windows.Media 
Imports Leadtools.Windows.Media.Effects 
 
Class DesaturateEffectExampleWindow 
   Inherits Window 
   Public Sub New() 
      Dim sp As New StackPanel() 
      Content = sp 
 
      Dim theViewer As New ImageViewer() 
 
      theViewer.HorizontalAlignment = HorizontalAlignment.Center 
      theViewer.VerticalAlignment = VerticalAlignment.Top 
      theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left 
      theViewer.ImageVerticalAlignment = VerticalAlignment.Top 
 
      sp.Children.Add(theViewer) 
 
      ' Create the sliders 
      Dim tb As New TextBlock() 
      tb.HorizontalAlignment = HorizontalAlignment.Center 
      tb.Text = "Saturation:" 
      sp.Children.Add(tb) 
 
      Dim theSlider As New Slider() 
      theSlider.Minimum = 0.0 
      theSlider.Maximum = 1.0 
      theSlider.Width = 400 
      theSlider.Orientation = Orientation.Horizontal 
      theSlider.IsSnapToTickEnabled = True 
      theSlider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight 
      theSlider.TickFrequency = 0.1 
      theSlider.AutoToolTipPrecision = 2 
      theSlider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight 
 
      sp.Children.Add(theSlider) 
 
      ' Load an image into the viewer 
      theViewer.Source = New BitmapImage(New Uri(System.IO.Path.Combine(LEAD_VARS.ImagesDir, "Cannon.jpg"))) 
 
      ' Create the effect 
      Dim effect As New DesaturateEffect() 
      effect.Saturation = 0.5 
      theViewer.ImageEffect = effect 
 
      ' Bind the properties 
      Dim bind As New Binding() 
      bind.Source = effect 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 
      bind.Path = New PropertyPath("Saturation") 
      theSlider.SetBinding(Slider.ValueProperty, bind) 
 
      Title = "Using DesaturateEffect" 
   End Sub 
End Class 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
c#[Silverlight C# Example] 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.Windows.Media; 
using Leadtools.Windows.Media.Effects; 
using Leadtools.Windows.Controls; 
 
class DesaturateEffectExampleWindow : UserControl 
{ 
   public DesaturateEffectExampleWindow() 
   { 
      StackPanel sp = new StackPanel(); 
      Content = sp; 
 
      ImageViewer theViewer = new ImageViewer(); 
 
      theViewer.HorizontalAlignment = HorizontalAlignment.Center; 
      theViewer.VerticalAlignment = VerticalAlignment.Top; 
      theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left; 
      theViewer.ImageVerticalAlignment = VerticalAlignment.Top; 
 
      sp.Children.Add(theViewer); 
 
      // Create the sliders 
      TextBlock tb = new TextBlock(); 
      tb.HorizontalAlignment = HorizontalAlignment.Center; 
      tb.Text = "Saturation:"; 
      sp.Children.Add(tb); 
 
      Slider theSlider = new Slider(); 
      theSlider.Minimum = 0.0; 
      theSlider.Maximum = 1.0; 
      theSlider.Width = 400; 
      theSlider.Orientation = Orientation.Horizontal; 
 
      sp.Children.Add(theSlider); 
 
      // Load an image into the viewer 
      theViewer.Source = new BitmapImage(new Uri(LeadtoolsExamples.Common.ImagesPath.Path + "Cannon.jpg")); 
 
      // Create the effect 
      DesaturateEffect effect = new DesaturateEffect(); 
      effect.Saturation = 0.5; 
      theViewer.ImageEffect = effect; 
 
      // Bind the properties 
      Binding bind = new Binding(); 
      bind.Source = effect; 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.Default; 
      bind.Path = new PropertyPath("Saturation"); 
      theSlider.SetBinding(Slider.ValueProperty, bind); 
   } 
} 
vb[Silverlight VB Example] 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.Windows.Controls 
Imports Leadtools.Windows.Media 
Imports Leadtools.Windows.Media.Effects 
 
Class DesaturateEffectExampleWindow 
   Inherits UserControl 
   Public Sub New() 
      Dim sp As New StackPanel() 
      Content = sp 
 
      Dim theViewer As New ImageViewer() 
 
      theViewer.HorizontalAlignment = HorizontalAlignment.Center 
      theViewer.VerticalAlignment = VerticalAlignment.Top 
      theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left 
      theViewer.ImageVerticalAlignment = VerticalAlignment.Top 
 
      sp.Children.Add(theViewer) 
 
      ' Create the sliders 
      Dim tb As New TextBlock() 
      tb.HorizontalAlignment = HorizontalAlignment.Center 
      tb.Text = "Saturation:" 
      sp.Children.Add(tb) 
 
      Dim theSlider As New Slider() 
      theSlider.Minimum = 0.0 
      theSlider.Maximum = 1.0 
      theSlider.Width = 400 
      theSlider.Orientation = Orientation.Horizontal 
 
      sp.Children.Add(theSlider) 
 
      ' Load an image into the viewer 
      theViewer.Source = New BitmapImage(New Uri(LeadtoolsExamples.Common.ImagesPath.Path + "Cannon.jpg")) 
 
      ' Create the effect 
      Dim effect As New DesaturateEffect() 
      effect.Saturation = 0.5 
      theViewer.ImageEffect = effect 
 
      ' Bind the properties 
      Dim bind As New Binding() 
      bind.Source = effect 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.Default 
      bind.Path = New PropertyPath("Saturation") 
      theSlider.SetBinding(Slider.ValueProperty, bind) 
 
   End Sub 
End Class 

Requirements

Target Platforms

Help Version 20.0.2020.3.31
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Windows.Media.Effects Assembly