How to change brightness of image on WPF image viewer?
In This Topic
For processing (for example, changing the brightness) an image in image viewer you need do the following steps:
- Create an instance of the WpfImageViewerProcessingTool class - a visual tool, which allows to process rectangular area in image viewer.
- Specify the image processing command, which must be used by visual tool for processing the image region in image viewer.
- Set the visual tool as the current tool of image viewer.
Here is C#/VB.NET code that shows how to change the brightness of visible area of
WpfImageViewer:
/// <summary>
/// Adds the visual tool, which changes brightness of visible area of image viewer, to the image viewer.
/// </summary>
/// <param name="imageViewer">The image viewer.</param>
/// <param name="imageBrightness">The image brightness value in percents. Valid values are from -100 to 100.</param>
public void AddVisualToolForProcessingVisibleAreaInImageViewer(
Vintasoft.Imaging.Wpf.UI.WpfImageViewer imageViewer,
int imageBrightness)
{
// create command for changing of image brightness
Vintasoft.Imaging.ImageProcessing.Color.ChangeBrightnessCommand changeBrightness =
new Vintasoft.Imaging.ImageProcessing.Color.ChangeBrightnessCommand();
// set the command parameters
changeBrightness.Brightness = imageBrightness;
// create an instance of the ImageViewerProcessingTool class
Vintasoft.Imaging.Wpf.UI.VisualTools.WpfImageViewerProcessingTool viewerProcessingTool =
new Vintasoft.Imaging.Wpf.UI.VisualTools.WpfImageViewerProcessingTool();
// specify that visual tool must use the command for processing visible area in image viewer
viewerProcessingTool.ProcessingCommand = changeBrightness;
// set the tool as the current tool of the ImageViewer
imageViewer.VisualTool = viewerProcessingTool;
}
''' <summary>
''' Adds the visual tool, which changes brightness of visible area of image viewer, to the image viewer.
''' </summary>
''' <param name="imageViewer">The image viewer.</param>
''' <param name="imageBrightness">The image brightness value in percents. Valid values are from -100 to 100.</param>
Public Sub AddVisualToolForProcessingVisibleAreaInImageViewer(imageViewer As Vintasoft.Imaging.Wpf.UI.WpfImageViewer, imageBrightness As Integer)
' create command for changing of image brightness
Dim changeBrightness As New Vintasoft.Imaging.ImageProcessing.Color.ChangeBrightnessCommand()
' set the command parameters
changeBrightness.Brightness = imageBrightness
' create an instance of the ImageViewerProcessingTool class
Dim viewerProcessingTool As New Vintasoft.Imaging.Wpf.UI.VisualTools.WpfImageViewerProcessingTool()
' specify that visual tool must use the command for processing visible area in image viewer
viewerProcessingTool.ProcessingCommand = changeBrightness
' set the tool as the current tool of the ImageViewer
imageViewer.VisualTool = viewerProcessingTool
End Sub