←Select platform

ContrastAdjustEffect Class

Summary

Enhances the image colors by adjusting the image brightness and contrast using specified values.

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

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 ContrastAdjustEffectExampleWindow : Window 
{ 
   public ContrastAdjustEffectExampleWindow() 
   { 
      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 = "Brightness:"; 
      sp.Children.Add(tb); 
 
      Slider brightnessSlider = new Slider(); 
      brightnessSlider.Minimum = 0.0; 
      brightnessSlider.Maximum = 2.0; 
      brightnessSlider.Width = 400; 
      brightnessSlider.Orientation = Orientation.Horizontal; 
      brightnessSlider.IsSnapToTickEnabled = true; 
      brightnessSlider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight; 
      brightnessSlider.TickFrequency = 0.1; 
      brightnessSlider.AutoToolTipPrecision = 2; 
      brightnessSlider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight; 
 
      sp.Children.Add(brightnessSlider); 
 
      tb = new TextBlock(); 
      tb.HorizontalAlignment = HorizontalAlignment.Center; 
      tb.Text = "Contrast:"; 
      sp.Children.Add(tb); 
 
      Slider contrastSlider = new Slider(); 
      contrastSlider.Minimum = 0.0; 
      contrastSlider.Maximum = 2.0; 
      contrastSlider.Width = 400; 
      contrastSlider.Orientation = Orientation.Horizontal; 
      contrastSlider.IsSnapToTickEnabled = true; 
      contrastSlider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight; 
      contrastSlider.TickFrequency = 0.1; 
      contrastSlider.AutoToolTipPrecision = 2; 
      contrastSlider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight; 
 
      sp.Children.Add(contrastSlider); 
 
      // Load an image into the viewer 
      theViewer.Source = new BitmapImage(new Uri(System.IO.Path.Combine(LEAD_VARS.ImagesDir, "Cannon.jpg"))); 
 
      // Create the effect 
      ContrastAdjustEffect effect = new ContrastAdjustEffect(); 
      effect.Brightness = 0.0; 
      effect.Contrast = 1.2; 
      theViewer.ImageEffect = effect; 
 
      // Bind the properties 
      Binding bind = new Binding(); 
      bind.Source = effect; 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; 
      bind.Path = new PropertyPath("Brightness"); 
      brightnessSlider.SetBinding(Slider.ValueProperty, bind); 
 
      bind = new Binding(); 
      bind.Source = effect; 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; 
      bind.Path = new PropertyPath("Contrast"); 
      contrastSlider.SetBinding(Slider.ValueProperty, bind); 
 
      Title = "Using ContrastAdjustEffect"; 
   } 
} 
 
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 ContrastAdjustEffectExampleWindow 
   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 = "Brightness:" 
      sp.Children.Add(tb) 
 
      Dim brightnessSlider As New Slider() 
      brightnessSlider.Minimum = 0.0 
      brightnessSlider.Maximum = 2.0 
      brightnessSlider.Width = 400 
      brightnessSlider.Orientation = Orientation.Horizontal 
      brightnessSlider.IsSnapToTickEnabled = True 
      brightnessSlider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight 
      brightnessSlider.TickFrequency = 0.1 
      brightnessSlider.AutoToolTipPrecision = 2 
      brightnessSlider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight 
 
      sp.Children.Add(brightnessSlider) 
 
      tb = New TextBlock() 
      tb.HorizontalAlignment = HorizontalAlignment.Center 
      tb.Text = "Contrast:" 
      sp.Children.Add(tb) 
 
      Dim contrastSlider As New Slider() 
      contrastSlider.Minimum = 0.0 
      contrastSlider.Maximum = 2.0 
      contrastSlider.Width = 400 
      contrastSlider.Orientation = Orientation.Horizontal 
      contrastSlider.IsSnapToTickEnabled = True 
      contrastSlider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight 
      contrastSlider.TickFrequency = 0.1 
      contrastSlider.AutoToolTipPrecision = 2 
      contrastSlider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.BottomRight 
 
      sp.Children.Add(contrastSlider) 
 
      ' 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 ContrastAdjustEffect() 
      effect.Brightness = 0.0 
      effect.Contrast = 1.2 
      theViewer.ImageEffect = effect 
 
      ' Bind the properties 
      Dim bind As New Binding() 
      bind.Source = effect 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 
      bind.Path = New PropertyPath("Brightness") 
      brightnessSlider.SetBinding(Slider.ValueProperty, bind) 
 
      bind = New Binding() 
      bind.Source = effect 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged 
      bind.Path = New PropertyPath("Contrast") 
      contrastSlider.SetBinding(Slider.ValueProperty, bind) 
 
      Title = "Using ContrastAdjustEffect" 
   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 ContrastAdjustEffectExampleWindow : UserControl 
{ 
   public ContrastAdjustEffectExampleWindow() 
   { 
      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 = "Brightness:"; 
      sp.Children.Add(tb); 
 
      Slider brightnessSlider = new Slider(); 
      brightnessSlider.Minimum = 0.0; 
      brightnessSlider.Maximum = 2.0; 
      brightnessSlider.Width = 400; 
      brightnessSlider.Orientation = Orientation.Horizontal; 
 
      sp.Children.Add(brightnessSlider); 
 
      tb = new TextBlock(); 
      tb.HorizontalAlignment = HorizontalAlignment.Center; 
      tb.Text = "Contrast:"; 
      sp.Children.Add(tb); 
 
      Slider contrastSlider = new Slider(); 
      contrastSlider.Minimum = 0.0; 
      contrastSlider.Maximum = 2.0; 
      contrastSlider.Width = 400; 
      contrastSlider.Orientation = Orientation.Horizontal; 
 
      sp.Children.Add(contrastSlider); 
 
      // Load an image into the viewer 
      theViewer.Source = new BitmapImage(new Uri(LeadtoolsExamples.Common.ImagesPath.Path + "Cannon.jpg")); 
 
      // Create the effect 
      ContrastAdjustEffect effect = new ContrastAdjustEffect(); 
      effect.Brightness = 0.0; 
      effect.Contrast = 1.2; 
      theViewer.ImageEffect = effect; 
 
      // Bind the properties 
      Binding bind = new Binding(); 
      bind.Source = effect; 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.Default; 
      bind.Path = new PropertyPath("Brightness"); 
      brightnessSlider.SetBinding(Slider.ValueProperty, bind); 
 
      bind = new Binding(); 
      bind.Source = effect; 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.Default; 
      bind.Path = new PropertyPath("Contrast"); 
      contrastSlider.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 ContrastAdjustEffectExampleWindow 
   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 = "Brightness:" 
      sp.Children.Add(tb) 
 
      Dim brightnessSlider As New Slider() 
      brightnessSlider.Minimum = 0.0 
      brightnessSlider.Maximum = 2.0 
      brightnessSlider.Width = 400 
      brightnessSlider.Orientation = Orientation.Horizontal 
 
      sp.Children.Add(brightnessSlider) 
 
      tb = New TextBlock() 
      tb.HorizontalAlignment = HorizontalAlignment.Center 
      tb.Text = "Contrast:" 
      sp.Children.Add(tb) 
 
      Dim contrastSlider As New Slider() 
      contrastSlider.Minimum = 0.0 
      contrastSlider.Maximum = 2.0 
      contrastSlider.Width = 400 
      contrastSlider.Orientation = Orientation.Horizontal 
 
      sp.Children.Add(contrastSlider) 
 
      ' 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 ContrastAdjustEffect() 
      effect.Brightness = 0.0 
      effect.Contrast = 1.2 
      theViewer.ImageEffect = effect 
 
      ' Bind the properties 
      Dim bind As New Binding() 
      bind.Source = effect 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.Default 
      bind.Path = New PropertyPath("Brightness") 
      brightnessSlider.SetBinding(Slider.ValueProperty, bind) 
 
      bind = New Binding() 
      bind.Source = effect 
      bind.UpdateSourceTrigger = UpdateSourceTrigger.Default 
      bind.Path = New PropertyPath("Contrast") 
      contrastSlider.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