GetColorCountCommand Class
Calculates the number of colors in an image.
This example shows how to load an image from disk and calculate the number of unique colors in the image.
Class GetColorCountCommandExample
Public Sub ProcessImage()
' [ do not forget to set your image file path here! ]
' create an image collection
Using images As New Vintasoft.Imaging.ImageCollection()
' add image to the image collection
images.Add("Deskew.tif")
Try
' create the image processing command
Dim command As New Vintasoft.Imaging.ImageProcessing.Info.GetColorCountCommand()
' subscribe to progress event of image processing command
AddHandler command.Progress, New System.EventHandler(Of Vintasoft.Imaging.ImageProcessing.ImageProcessingProgressEventArgs)(AddressOf command_Progress)
Try
' for each image in image collection
For Each image As Vintasoft.Imaging.VintasoftImage In images
' apply the image processing command to the image
command.ExecuteInPlace(image)
' show result
System.Windows.Forms.MessageBox.Show(String.Format("Image has {0} unique colors.", command.ColorCount))
Next
Catch ex As Vintasoft.Imaging.ImageProcessing.ImageProcessingException
' show error message
System.Windows.Forms.MessageBox.Show(ex.Message)
Return
End Try
Finally
images.ClearAndDisposeItems()
End Try
End Using
End Sub
Private Sub command_Progress(sender As Object, e As Vintasoft.Imaging.ImageProcessing.ImageProcessingProgressEventArgs)
' update progress info using e.Progress property
' ...
' cancel execution of command using e.Cancel property if necessary
' ...
End Sub
End Class
class GetColorCountCommandExample
{
public void ProcessImage()
{
// [ do not forget to set your image file path here! ]
// create an image collection
using (Vintasoft.Imaging.ImageCollection images = new Vintasoft.Imaging.ImageCollection())
{
// add image to the image collection
images.Add("Deskew.tif");
try
{
// create the image processing command
Vintasoft.Imaging.ImageProcessing.Info.GetColorCountCommand command =
new Vintasoft.Imaging.ImageProcessing.Info.GetColorCountCommand();
// subscribe to progress event of image processing command
command.Progress +=
new System.EventHandler<Vintasoft.Imaging.ImageProcessing.ImageProcessingProgressEventArgs>(command_Progress);
try
{
// for each image in image collection
foreach (Vintasoft.Imaging.VintasoftImage image in images)
{
// apply the image processing command to the image
command.ExecuteInPlace(image);
// show result
System.Windows.Forms.MessageBox.Show(string.Format("Image has {0} unique colors.", command.ColorCount));
}
}
catch (Vintasoft.Imaging.ImageProcessing.ImageProcessingException ex)
{
// show error message
System.Windows.Forms.MessageBox.Show(ex.Message);
return;
}
}
finally
{
images.ClearAndDisposeItems();
}
}
}
void command_Progress(object sender, Vintasoft.Imaging.ImageProcessing.ImageProcessingProgressEventArgs e)
{
// update progress info using e.Progress property
// ...
// cancel execution of command using e.Cancel property if necessary
// ...
}
}
Target Platforms: .NET 7; .NET 6; .NET 5; .NET Core 3.1; .NET Framework 4.8, 4.7, 4.6, 4.5, 4.0, 3.5