LEADTOOLS Support
Imaging
Imaging SDK Examples
Code Tip: How to determine if an image is Color, Black & White, or Grayscale using LEADTOOLS
#1
Posted
:
Monday, June 5, 2017 8:42:35 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 39
Thanks: 2 times
Was thanked: 3 time(s) in 3 post(s)
If you have a need to automatically detect the color type of input files in your application you could write a routine that looks at individual pixel color values and iterate through each pixel row by row, coloumn by column but who has time for that. Instead, you can use the LEADTOOLS
ImageColorTypeCommand. The following code snippet will return the detected image color type and the associated confidence.
Code:public void detectColorType()
{
using (RasterCodecs codecs = new RasterCodecs())
{
RasterImage image = codecs.Load(@"PATH TO IMAGE FILE");
ImageColorTypeCommand command = new ImageColorTypeCommand();
command.Run(image);
Console.WriteLine($"Color Type: {command.ColorType}\nConfidence: {command.Confidence}");
}
}
The output from this code will be an
ImageColorType (Color, BlackAndWhite, GrayScale or none).
Roberto Rodriguez
Developer Support Engineer
LEAD Technologies, Inc.
#2
Posted
:
Friday, August 31, 2018 8:42:37 AM(UTC)
Groups: Registered, Tech Support, Administrators
Posts: 89
Was thanked: 4 time(s) in 4 post(s)
ColorTypeCommand from v20 LEADTOOLS Online Documentation.
Attached is a fully functioning sample application that utilizes the code snippet provided from the post above.
The project uses the LEADTOOLS v20 SDK.
The Leadtools.Pdf.dll is included to work with PDF files. Other Codices may need to be added to work with the various types of file formats that LEADTOOLS Supports.
Chris Thompson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS Support
Imaging
Imaging SDK Examples
Code Tip: How to determine if an image is Color, Black & White, or Grayscale using LEADTOOLS
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.