ColorThresholdCommand Class
Summary
Using any one of eight color spaces, resets those image's pixel component values that fall inside or outside of a specified range.
Syntax
C#
VB
Java
Objective-C
WinRT C#
C++
@interface LTColorThresholdCommand : LTRasterCommand
public class ColorThresholdCommand extends RasterCommand
function Leadtools.ImageProcessing.Color.ColorThresholdCommand()
Example
Run the ColorThresholdCommand on an image.
C#
VB
WinRT C#
Silverlight C#
Silverlight VB
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing.Color
Public Sub ColorThresholdCommandExample()
Dim codecs As New RasterCodecs()
codecs.ThrowExceptionsOnInvalidImages = True
Dim leadImage As RasterImage = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "ImageProcessingDemo\\Image1.jpg"))
' Prepare the command
Dim components() As ColorThresholdCommandComponent
ReDim components(2)
components(0) = New ColorThresholdCommandComponent
components(1) = New ColorThresholdCommandComponent
components(2) = New ColorThresholdCommandComponent
components(0).MinimumRange = 128
components(0).MaximumRange = 255
components(0).Flags = 0
components(1).MinimumRange = 128
components(1).MaximumRange = 255
components(1).Flags = 0
components(2).MinimumRange = 128
components(2).MaximumRange = 255
components(2).Flags = 0
Dim command As ColorThresholdCommand = New ColorThresholdCommand(ColorThresholdCommandType.Rgb, components)
'Apply color Threshold effect on the image.
command.Run(leadImage)
codecs.Save(leadImage, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24)
End Sub
Public NotInheritable Class LEAD_VARS
Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing.Color;
public void ColorThresholdCommandExample()
{
// Load an image
RasterCodecs codecs = new RasterCodecs();
codecs.ThrowExceptionsOnInvalidImages = true;
RasterImage image = codecs.Load(Path.Combine(LEAD_VARS.ImagesDir, "ImageProcessingDemo\\Image1.jpg"));
// Prepare the command
ColorThresholdCommandComponent[] Components = new ColorThresholdCommandComponent[3];
Components[0] = new ColorThresholdCommandComponent();
Components[0].MinimumRange = 128;
Components[0].MaximumRange = 255;
Components[0].Flags = 0;
Components[1] = new ColorThresholdCommandComponent();
Components[1].MinimumRange = 128;
Components[1].MaximumRange = 255;
Components[1].Flags = 0;
Components[2] = new ColorThresholdCommandComponent();
Components[2].MinimumRange = 128;
Components[2].MaximumRange = 255;
Components[2].Flags = 0;
ColorThresholdCommand command = new ColorThresholdCommand(ColorThresholdCommandType.Rgb, Components);
//Apply color Threshold effect on the image.
command.Run(image);
codecs.Save(image, Path.Combine(LEAD_VARS.ImagesDir, "Result.jpg"), RasterImageFormat.Jpeg, 24);
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing.Color;
public async Task ColorThresholdCommandExample()
{
// Load an image
RasterCodecs codecs = new RasterCodecs();
codecs.ThrowExceptionsOnInvalidImages = true;
// Load the image
string srcFileName = @"Assets\Image1.cmp";
StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));
// Prepare the command
ColorThresholdCommandComponent[] Components = new ColorThresholdCommandComponent[3];
Components[0] = new ColorThresholdCommandComponent();
Components[0].MinimumRange = 128;
Components[0].MaximumRange = 255;
Components[0].Flags = 0;
Components[1] = new ColorThresholdCommandComponent();
Components[1].MinimumRange = 128;
Components[1].MaximumRange = 255;
Components[1].Flags = 0;
Components[2] = new ColorThresholdCommandComponent();
Components[2].MinimumRange = 128;
Components[2].MaximumRange = 255;
Components[2].Flags = 0;
ColorThresholdCommand command = new ColorThresholdCommand(ColorThresholdCommandType.Rgb, Components);
//Apply color Threshold effect on the image.
command.Run(image);
string destFileName = @"result.jpg";
StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName);
await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Jpeg, 0);
}
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing.Color;
using Leadtools.Examples;
public void ColorThresholdCommandExample(RasterImage image, Stream outStream)
{
// Prepare the command
ColorThresholdCommandComponent[] Components = new ColorThresholdCommandComponent[3];
Components[0] = new ColorThresholdCommandComponent();
Components[0].MinimumRange = 128;
Components[0].MaximumRange = 255;
Components[0].Flags = 0;
Components[1] = new ColorThresholdCommandComponent();
Components[1].MinimumRange = 128;
Components[1].MaximumRange = 255;
Components[1].Flags = 0;
Components[2] = new ColorThresholdCommandComponent();
Components[2].MinimumRange = 128;
Components[2].MaximumRange = 255;
Components[2].Flags = 0;
ColorThresholdCommand command = new ColorThresholdCommand(ColorThresholdCommandType.Rgb, Components);
//Apply color Threshold effect on the image.
command.Run(image);
// Save result image
RasterCodecs codecs = new RasterCodecs();
codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24);
image.Dispose();
}
Imports Leadtools
Imports Leadtools.Codecs
Imports Leadtools.ImageProcessing.Color
Public Sub ColorThresholdCommandExample(ByVal image As RasterImage, ByVal outStream As Stream)
' Prepare the command
Dim Components As ColorThresholdCommandComponent() = New ColorThresholdCommandComponent(2){}
Components(0) = New ColorThresholdCommandComponent()
Components(0).MinimumRange = 128
Components(0).MaximumRange = 255
Components(0).Flags = 0
Components(1) = New ColorThresholdCommandComponent()
Components(1).MinimumRange = 128
Components(1).MaximumRange = 255
Components(1).Flags = 0
Components(2) = New ColorThresholdCommandComponent()
Components(2).MinimumRange = 128
Components(2).MaximumRange = 255
Components(2).Flags = 0
Dim command As ColorThresholdCommand = New ColorThresholdCommand(ColorThresholdCommandType.Rgb, Components)
'Apply color Threshold effect on the image.
command.Run(image)
' Save result image
Dim codecs As RasterCodecs = New RasterCodecs()
codecs.Save(image, outStream, RasterImageFormat.Jpeg, 24)
image.Dispose()
End Sub