public GrayscaleCommand()
- (instancetype)init
public GrayscaleCommand()
public:
GrayscaleCommand();
__init__() # Default constructor
using Leadtools;
using Leadtools.Codecs;
using Leadtools.ImageProcessing;
public void GrayscaleCommandExample()
{
RasterCodecs codecs = new RasterCodecs();
string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
string destFileName8 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_grayscale8.jpg");
string destFileName12 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_grayscale12.jpg");
string destFileName16 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_grayscale16.jpg");
// Load the source image from disk as 24-bits/pixel
RasterImage image = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1);
// Check the grayscale mode
Console.WriteLine("Grsyscale mode of original image = {0}", image.GrayscaleMode);
// Convert to 8-bit grayscale
GrayscaleCommand command = new GrayscaleCommand();
command.BitsPerPixel = 8;
command.Run(image);
// Check the grayscale mode
Console.WriteLine("Grsyscale mode after grayscale command with 8 bpp = {0}", image.GrayscaleMode);
// Save it to disk
codecs.Options.Jpeg.Save.QualityFactor = 2;
codecs.Save(image, destFileName8, RasterImageFormat.Jpeg, 8);
image.Dispose();
// Load the image again this time grayscale to 12-bits/pixel
image = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1);
command.BitsPerPixel = 12;
command.Run(image);
Console.WriteLine("Grsyscale mode after grayscale command with 12 bpp = {0}", image.GrayscaleMode);
codecs.Options.Jpeg.Save.QualityFactor = 2;
codecs.Save(image, destFileName12, RasterImageFormat.Jpeg, 12);
image.Dispose();
// Load the image again this time grayscale to 16-bits/pixel
image = codecs.Load(srcFileName, 24, CodecsLoadByteOrder.Bgr, 1, 1);
command.BitsPerPixel = 16;
command.Run(image);
Console.WriteLine("Grsyscale mode after grayscale command with 16 bpp = {0}", image.GrayscaleMode);
// When saving 16-bit jpegs, you must use lossless quality factor
codecs.Options.Jpeg.Save.QualityFactor = 0;
codecs.Save(image, destFileName16, RasterImageFormat.Jpeg, 16);
image.Dispose();
// Clean Up
codecs.Dispose();
}
static class LEAD_VARS
{
public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images";
}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
Your email has been sent to support! Someone should be in touch! If your matter is urgent please come back into chat.
Chat Hours:
Monday - Friday, 8:30am to 6pm ET
Thank you for your feedback!
Please fill out the form again to start a new chat.
All agents are currently offline.
Chat Hours:
Monday - Friday
8:30AM - 6PM EST
To contact us please fill out this form and we will contact you via email.