LEADTOOLS (Leadtools assembly)
LEAD Technologies, Inc

ColorResolutionCommand Class

Example 





Members 
Converts an image from any bits-per-pixel to any bits-per-pixel. .NET support Silverlight support WinRT support
Object Model
ColorResolutionCommand ClassRasterImage Class
Syntax
public class ColorResolutionCommand : RasterCommand, IRasterCommand  
'Declaration
 
Public Class ColorResolutionCommand 
   Inherits RasterCommand
   Implements IRasterCommand 
'Usage
 
Dim instance As ColorResolutionCommand
public sealed class ColorResolutionCommand : IRasterCommand  
function Leadtools.ImageProcessing.ColorResolutionCommand()
public ref class ColorResolutionCommand : public RasterCommand, IRasterCommand  
Remarks

This class provides flexibility in specifying the output destination and in specifying the palette to use.

For general information about dithering, refer to Color Resolution and Dithering and Dithering Methods.

You can convert the image in place or create a new converted image.

In specifying a palette, you can use simple palette options, or you can specify a palette that is tailored to your needs. The tailored palette can be any size that you specify. It can include specific colors, reserved blank entries, and open entries that this method fills with optimized colors.

If you use the same tailored palette more than once, you can improve performance by creating a table, using RasterUserMatchTable.

NOTE: Using this class to change the color order of a 24-bit or 32-bit image (i.e. RGB to BGR) will have no effect on the image when painting or saving (to a file). If you want to change the visual appearance, you can simply swap the color order using the RasterImage.Order property.

When converting to 32 and 64-bit images, you can control whether to initialize the alpha channel values to all 0's or 1's through the InitAlpha property.

This class does not support signed data images. An exception will be thrown if a signed data image is passed to this class.

For more information, refer to Introduction to Image Processing With LEADTOOLS.

For more information, refer to Introduction - Palette Handling.

Example
 
Public Sub ColorResolutionCommandExample()
      Dim codecs As RasterCodecs = New RasterCodecs()

      Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp")
      Dim destFileName1 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_colorres8.bmp")
      Dim destFileName2 As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1_colorres4.bmp")

      ' Load the source image from disk
      Dim image As RasterImage = codecs.Load(srcFileName)

      ' First color-res it to 8 bits per pixel  using the Netscape palette into a seperate image
      Dim cmd As ColorResolutionCommand = New ColorResolutionCommand()
      cmd.Mode = ColorResolutionCommandMode.CreateDestinationImage
      cmd.BitsPerPixel = 8
      cmd.Order = RasterByteOrder.Rgb
      cmd.DitheringMethod = RasterDitheringMethod.None
      cmd.PaletteFlags = ColorResolutionCommandPaletteFlags.UsePalette
      cmd.SetPalette(RasterPalette.Netscape())
      cmd.Run(image)

      Dim destImage As RasterImage = cmd.DestinationImage
      Debug.Assert(destImage.BitsPerPixel = 8)

      ' Save it to disk
      codecs.Save(destImage, destFileName1, RasterImageFormat.Bmp, 8)
      destImage.Dispose()

      ' Now color-res the image in-place to 4-bits per pixel using the Optimized palette
      cmd.Mode = ColorResolutionCommandMode.InPlace
      cmd.BitsPerPixel = 4
      cmd.Order = RasterByteOrder.Rgb
      cmd.DitheringMethod = RasterDitheringMethod.None
      cmd.PaletteFlags = ColorResolutionCommandPaletteFlags.Optimized
      cmd.Run(image)
      Debug.Assert(image.BitsPerPixel = 4)

      ' Save it to disk
      codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 4)
      destImage.Dispose()

      ' Clean Up
      image.Dispose()
   End Sub

Public NotInheritable Class LEAD_VARS
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images"
End Class
public void ColorResolutionCommandExample()
   {
      RasterCodecs codecs = new RasterCodecs();

      string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp");
      string destFileName1 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_colorres8.bmp");
      string destFileName2 = Path.Combine(LEAD_VARS.ImagesDir, "Image1_colorres4.bmp");

      // Load the source image from disk
      RasterImage image = codecs.Load(srcFileName);

      // First color-res it to 8 bits per pixel  using the Netscape palette into a seperate image
      ColorResolutionCommand cmd = new ColorResolutionCommand();
      cmd.Mode = ColorResolutionCommandMode.CreateDestinationImage;
      cmd.BitsPerPixel = 8;
      cmd.Order = RasterByteOrder.Rgb;
      cmd.DitheringMethod = RasterDitheringMethod.None;
      cmd.PaletteFlags = ColorResolutionCommandPaletteFlags.UsePalette;
      cmd.SetPalette(RasterPalette.Netscape());
      cmd.Run(image);

      RasterImage destImage = cmd.DestinationImage;
      Debug.Assert(destImage.BitsPerPixel == 8);

      // Save it to disk
      codecs.Save(destImage, destFileName1, RasterImageFormat.Bmp, 8);
      destImage.Dispose();

      // Now color-res the image in-place to 4-bits per pixel using the Optimized palette
      cmd.Mode = ColorResolutionCommandMode.InPlace;
      cmd.BitsPerPixel = 4;
      cmd.Order = RasterByteOrder.Rgb;
      cmd.DitheringMethod = RasterDitheringMethod.None;
      cmd.PaletteFlags = ColorResolutionCommandPaletteFlags.Optimized;
      cmd.Run(image);
      Debug.Assert(image.BitsPerPixel == 4);

      // Save it to disk
      codecs.Save(image, destFileName2, RasterImageFormat.Bmp, 4);
      destImage.Dispose();

      // Clean Up
      image.Dispose();
   }

static class LEAD_VARS
{
   public const string ImagesDir = @"C:\Users\Public\Documents\LEADTOOLS Images";
}
RasterCommandExamples.prototype.ColorResolutionCommandExample = function () {
    Tools.SetLicense();
    with (Leadtools) {
        with (Leadtools.Codecs) {
            with (Leadtools.ImageProcessing) {
                var codecs = new RasterCodecs();

                var srcFileName = "Assets\\Image1.cmp";
                var destFileName1 = "Image1_colorres8.bmp";
                var destFileName2 = "Image1_colorres4.bmp";
                var image;
                var destImage;
                var cmd;
                // Load the source image from disk
                return Tools.AppInstallFolder().getFileAsync(srcFileName).then(function (loadFile) {
                    return codecs.loadAsync(LeadStreamFactory.create(loadFile))
                })
                    .then(function (img) {
                        image = img;
                        // First color-res it to 8 bits per pixel  using the Netscape palette into a seperate image
                        cmd = new ColorResolutionCommand();
                        cmd.mode = ColorResolutionCommandMode.createDestinationImage;
                        cmd.bitsPerPixel = 8;
                        cmd.order = RasterByteOrder.rgb;
                        cmd.ditheringMethod = RasterDitheringMethod.none;
                        cmd.paletteFlags = ColorResolutionCommandPaletteFlags.netscape;
                        cmd.run (image);

                        destImage = cmd.destinationImage;
                        console.assert(destImage.bitsPerPixel === 8, "destImage.bitsPerPixel === 8");

                        // Save it to disk
                        return Tools.AppLocalFolder().createFileAsync(destFileName1)
                    })
                        .then(function (saveFile) {
                            return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.bmp, 8)
                        })
                        .then(function () {
                            destImage.close();

                            // Now color-res the image in-place to 4-bits per pixel using the Optimized palette
                            cmd.mode = ColorResolutionCommandMode.inPlace;
                            cmd.bitsPerPixel = 4;
                            cmd.order = RasterByteOrder.rgb;
                            cmd.ditheringMethod = RasterDitheringMethod.none;
                            cmd.paletteFlags = ColorResolutionCommandPaletteFlags.optimized;
                            cmd.run(image);
                            console.assert(image.bitsPerPixel === 4, "image.bitsPerPixel === 4");

                            // Save it to disk
                            return Tools.AppLocalFolder().createFileAsync(destFileName2)
                        })
                        .then(function (saveFile) {
                            return codecs.saveAsync(image, LeadStreamFactory.create(saveFile), RasterImageFormat.bmp, 4)
                        })
                        .then(function () {
                            destImage.close();

                            // Clean Up
                            image.close();
                            codecs.close();
                        });
            }
        }
    }
}
[TestMethod]
public async Task ColorResolutionCommandExample()
{
   RasterCodecs codecs = new RasterCodecs();
   string srcFileName = @"Assets\Image1.cmp";
   string destFileName1 = @"Image1_colorres8.bmp";
   string destFileName2 = @"Image1_colorres4.bmp";

   // Load the source image from disk
   StorageFile loadFile = await Tools.AppInstallFolder.GetFileAsync(srcFileName);
   RasterImage image = await codecs.LoadAsync(LeadStreamFactory.Create(loadFile));

   // First color-res it to 8 bits per pixel  using the Netscape palette into a seperate image
   ColorResolutionCommand cmd = new ColorResolutionCommand();
   cmd.Mode = ColorResolutionCommandMode.CreateDestinationImage;
   cmd.BitsPerPixel = 8;
   cmd.Order = RasterByteOrder.Rgb;
   cmd.DitheringMethod = RasterDitheringMethod.None;
   cmd.PaletteFlags = ColorResolutionCommandPaletteFlags.Netscape;
   cmd.Run(image);

   RasterImage destImage = cmd.DestinationImage;
   Assert.IsTrue(destImage.BitsPerPixel == 8);

   // Save it to disk
   StorageFile saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName1);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, 8);
   destImage.Dispose();

   // Now color-res the image in-place to 4-bits per pixel using the Optimized palette
   cmd.Mode = ColorResolutionCommandMode.InPlace;
   cmd.BitsPerPixel = 4;
   cmd.Order = RasterByteOrder.Rgb;
   cmd.DitheringMethod = RasterDitheringMethod.None;
   cmd.PaletteFlags = ColorResolutionCommandPaletteFlags.Optimized;
   cmd.Run(image);
   Assert.IsTrue(image.BitsPerPixel == 4);

   // Save it to disk
   saveFile = await Tools.AppLocalFolder.CreateFileAsync(destFileName2);
   await codecs.SaveAsync(image, LeadStreamFactory.Create(saveFile), RasterImageFormat.Bmp, 4);
   destImage.Dispose();

   // Clean Up
   image.Dispose();
}
public void ColorResolutionCommandExample(RasterImage image, Stream destStream8, Stream destStream4)
{
   RasterCodecs codecs = new RasterCodecs();
   // First color-res it to 8 bits per pixel  using the Netscape palette into a seperate image
   ColorResolutionCommand cmd = new ColorResolutionCommand();
   cmd.Mode = ColorResolutionCommandMode.CreateDestinationImage;
   cmd.BitsPerPixel = 8;
   cmd.Order = RasterByteOrder.Rgb;
   cmd.DitheringMethod = RasterDitheringMethod.None;
   cmd.PaletteFlags = ColorResolutionCommandPaletteFlags.UsePalette;
   cmd.SetPalette(RasterPalette.Netscape());
   cmd.Run(image);

   RasterImage destImage = cmd.DestinationImage;
   Debug.Assert(destImage.BitsPerPixel == 8);

   // Save it to disk
   codecs.Save(destImage, destStream8, RasterImageFormat.Bmp, 8);
   destImage.Dispose();

   // Now color-res the image in-place to 4-bits per pixel using the Optimized palette
   cmd.Mode = ColorResolutionCommandMode.InPlace;
   cmd.BitsPerPixel = 4;
   cmd.Order = RasterByteOrder.Rgb;
   cmd.DitheringMethod = RasterDitheringMethod.None;
   cmd.PaletteFlags = ColorResolutionCommandPaletteFlags.Optimized;
   cmd.Run(image);
   Debug.Assert(image.BitsPerPixel == 4);

   // Save it to disk
   codecs.Save(image, destStream4, RasterImageFormat.Bmp, 4);
   destImage.Dispose();

   // Clean Up
   image.Dispose();
}
Public Sub ColorResolutionCommandExample(ByVal image As RasterImage, ByVal destStream8 As Stream, ByVal destStream4 As Stream)
   Dim codecs As RasterCodecs = New RasterCodecs()
   ' First color-res it to 8 bits per pixel  using the Netscape palette into a seperate image
   Dim cmd As ColorResolutionCommand = New ColorResolutionCommand()
   cmd.Mode = ColorResolutionCommandMode.CreateDestinationImage
   cmd.BitsPerPixel = 8
   cmd.Order = RasterByteOrder.Rgb
   cmd.DitheringMethod = RasterDitheringMethod.None
   cmd.PaletteFlags = ColorResolutionCommandPaletteFlags.UsePalette
   cmd.SetPalette(RasterPalette.Netscape())
   cmd.Run(image)

   Dim destImage As RasterImage = cmd.DestinationImage
   Debug.Assert(destImage.BitsPerPixel = 8)

   ' Save it to disk
   codecs.Save(destImage, destStream8, RasterImageFormat.Bmp, 8)
   destImage.Dispose()

   ' Now color-res the image in-place to 4-bits per pixel using the Optimized palette
   cmd.Mode = ColorResolutionCommandMode.InPlace
   cmd.BitsPerPixel = 4
   cmd.Order = RasterByteOrder.Rgb
   cmd.DitheringMethod = RasterDitheringMethod.None
   cmd.PaletteFlags = ColorResolutionCommandPaletteFlags.Optimized
   cmd.Run(image)
   Debug.Assert(image.BitsPerPixel = 4)

   ' Save it to disk
   codecs.Save(image, destStream4, RasterImageFormat.Bmp, 4)
   destImage.Dispose()

   ' Clean Up
   image.Dispose()
End Sub
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

ColorResolutionCommand Members
Leadtools.ImageProcessing Namespace
Introduction to Image Processing With LEADTOOLS
Dithering Methods
Codecs.CodecsThumbnailOptions.DitheringMethod property
ImageProcessing.ColorResolutionCommand.DitheringMethod property
RasterDitheringMethod enumeration
RasterDefaults.DitheringMethod property
RasterImage.DitheringMethod property
RasterImage.DitherLine method
RasterImage.StartDithering method
RasterImage.StopDithering method
RasterBufferConverter.Convert
Convert

 

 


Products | Support | Contact Us | Copyright Notices

© 2006-2012 All Rights Reserved. LEAD Technologies, Inc.