The InvertEffect Class supports WPF/Silverlight.
Inverts the colors in the specified image, giving it the appearance of a photographic negative. Supported in SilverlightVisual Basic (Declaration) | |
---|---|
Public Class InvertEffect Inherits System.Windows.Media.Effects.ShaderEffect Implements IAnimatable |
Visual Basic (Usage) | Copy Code |
---|---|
Dim instance As InvertEffect |
C# | |
---|---|
public class InvertEffect : System.Windows.Media.Effects.ShaderEffect, IAnimatable |
C++/CLI | |
---|---|
public ref class InvertEffect : public System.Windows.Media.Effects.ShaderEffect, IAnimatable |
Visual Basic | Copy Code |
---|---|
Class InvertEffectExampleWindow Inherits Window Private theViewer As ImageViewer Public Sub New() Dim sp As New StackPanel() Content = sp theViewer = New ImageViewer() theViewer.HorizontalAlignment = HorizontalAlignment.Center theViewer.VerticalAlignment = VerticalAlignment.Top theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left theViewer.ImageVerticalAlignment = VerticalAlignment.Top sp.Children.Add(theViewer) ' Load an image into the viewer theViewer.Source = New BitmapImage(New Uri(System.IO.Path.Combine(LEAD_VARS.ImagesDir, "Cannon.jpg"))) Title = "Double click to use the Effect" AddHandler theViewer.MouseDoubleClick, AddressOf theViewer_MouseDoubleClick End Sub Private Sub theViewer_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseButtonEventArgs) Dim effect As New InvertEffect() theViewer.ImageEffect = effect Title = "Using InvertEffect" End Sub End Class Public NotInheritable Class LEAD_VARS Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" End Class |
C# | Copy Code |
---|---|
class InvertEffectExampleWindow : Window { private ImageViewer theViewer; public InvertEffectExampleWindow() { StackPanel sp = new StackPanel(); Content = sp; theViewer = new ImageViewer(); theViewer.HorizontalAlignment = HorizontalAlignment.Center; theViewer.VerticalAlignment = VerticalAlignment.Top; theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left; theViewer.ImageVerticalAlignment = VerticalAlignment.Top; sp.Children.Add(theViewer); // Load an image into the viewer theViewer.Source = new BitmapImage(new Uri(System.IO.Path.Combine(LEAD_VARS.ImagesDir, "Cannon.jpg"))); Title = "Double click to use the Effect"; theViewer.MouseDoubleClick += new MouseButtonEventHandler(theViewer_MouseDoubleClick); } private void theViewer_MouseDoubleClick(object sender, MouseButtonEventArgs e) { InvertEffect effect = new InvertEffect(); theViewer.ImageEffect = effect; Title = "Using InvertEffect"; } } static class LEAD_VARS { public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images"; } |
SilverlightCSharp | Copy Code |
---|---|
class InvertEffectExampleWindow : UserControl { private ImageViewer theViewer; public InvertEffectExampleWindow() { StackPanel sp = new StackPanel(); Content = sp; theViewer = new ImageViewer(); theViewer.HorizontalAlignment = HorizontalAlignment.Center; theViewer.VerticalAlignment = VerticalAlignment.Top; theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left; theViewer.ImageVerticalAlignment = VerticalAlignment.Top; sp.Children.Add(theViewer); // Load an image into the viewer theViewer.Source = new BitmapImage(new Uri(LeadtoolsExamples.Common.ImagesPath.Path + "Cannon.jpg")); //theViewer.MouseDoubleClick += new MouseButtonEventHandler(theViewer_MouseDoubleClick); } private void theViewer_MouseDoubleClick(object sender, MouseButtonEventArgs e) { InvertEffect effect = new InvertEffect(); theViewer.ImageEffect = effect; } } |
SilverlightVB | Copy Code |
---|---|
Class InvertEffectExampleWindow Inherits UserControl Private theViewer As ImageViewer Public Sub New() Dim sp As New StackPanel() Content = sp theViewer = New ImageViewer() theViewer.HorizontalAlignment = HorizontalAlignment.Center theViewer.VerticalAlignment = VerticalAlignment.Top theViewer.ImageHorizontalAlignment = HorizontalAlignment.Left theViewer.ImageVerticalAlignment = VerticalAlignment.Top sp.Children.Add(theViewer) ' Load an image into the viewer theViewer.Source = New BitmapImage(New Uri(LeadtoolsExamples.Common.ImagesPath.Path + "Cannon.jpg")) End Sub Private Sub theViewer_MouseDoubleClick(ByVal sender As Object, ByVal e As MouseButtonEventArgs) Dim effect As New InvertEffect() theViewer.ImageEffect = effect End Sub End Class |
XAML | Copy Code |
---|---|
<Window x:Class="InvertEffectExample" Height="600" Width="800" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:leadControls="clr-namespace:Leadtools.Windows.Controls;assembly=Leadtools.Windows.Controls" xmlns:leadEffects="clr-namespace:Leadtools.Windows.Media.Effects;assembly=Leadtools.Windows.Media.Effects"> <StackPanel> <leadControls:ImageViewer HorizontalAlignment="Center" VerticalAlignment="Top" ImageHorizontalAlignment="Left" ImageVerticalAlignment="Top" Source="file:///c:\users\Public\Documents\LEADTOOLS Images\cannon.jpg"> <leadControls:ImageViewer.ImageEffect> <leadEffects:InvertEffect /> </leadControls:ImageViewer.ImageEffect> </leadControls:ImageViewer> </StackPanel> </Window> |
This class can also be used to invert the color of a 1-bit image, making the black white and the white black.
System.Object
System.Windows.Threading.DispatcherObject
System.Windows.DependencyObject
System.Windows.Freezable
System.Windows.Media.Animation.Animatable
System.Windows.Media.Effects.Effect
System.Windows.Media.Effects.ShaderEffect
Leadtools.Windows.Media.Effects.InvertEffect
Target Platforms: Silverlight 3.0, Windows XP, Windows Server 2003 family, Windows Server 2008 family, Windows Vista, Windows 7, MAC OS/X (Intel Only)