In This Topic ▼

ColorResolutionCommand and Optimized Options

The palette supplied must be an array of Leadtools.RasterColor structures which have four one-byte fields:

Leadtools.ImageProcessing.ColorResolutionCommand, which maps the pixel values of the image to the palette entries, can also fill in some entries with optimized colors by specifying the ColorResolutionCommandPaletteFlags.Optimized flag in the ColorResolutionCommand.PaletteFlags property. The Reserved color of the Leadtools.RasterColor structure controls whether the command fills in that entry and if it maps any pixel values to that entry, as shown in the following table:

Value Meaning
0x01 (or RasterColor.ReservedColor) Reserved palette entry - Do not map any pixel values to this entry. Use this value to reserve the entry for later use.
0x02 (or RasterColor.EmptyColor) Empty palette entry - Let the command fill in the color. The command supplies optimized colors to fill and map pixel values to these entries.
0 Regular palette entry - Map pixel values to the supplied color. Make sure to define the RasterColor.R, RasterColor.G, RasterColor.B entries in this case.
Example
C#
// This C# example assumes 'image' is a 24/32/48/64-bit bitmap. It will convert it to an optimized palette of 255 colors.  
// In this case, pick a color for 'palette[0]' and let the other 255 entries be filled by ColorResolutionCommand.  
 
private static void TestCustomOptimizedPalette(RasterImage image) 
{ 
   RasterColor[] palette = new RasterColor[256]; 
 
   // Pick a color for the first palette entry (for example, a bitmap with a transparent color).  
   // In this case, set this entry to a color that is not in the image and then fill the transparent area with this color.  
 
   palette[0] = new RasterColor(1, 1, 1); 
   palette[0].Reserved = RasterColor.Reserved; // ColorResolutionCommand should ignore this color when generating the optimized palette  
   
   // Mark all the other palette entries as empty, so ColorResolutionCommand will fill them  
   for (int i = 1; i <= 255; i++) 
      palette[i].Reserved = RasterColor.EmptyColor; // or palette[i].IsEmptyColor = true  
 
   ColorResolutionCommand cmd = 
   new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 
                              8, 
                              RasterByteOrder.Rgb, 
                              RasterDitheringMethod.FloydStein, 
                              ColorResolutionCommandPaletteFlags.Optimized, 
                              null); 
   cmd.SetPalette(palette); 
                            
   cmd.Run(image); 
    
   // Now 'image' is an 8-bit image with a palette. If you do 'RasterColor[] imagePalette = image.GetPalette()': 
   //   - imagePalette[0] should be the selected color 
   //   - imagePalette[1], imagePalette[2], ... imagePalette[255] should be various colors chosen by the ColorResolution command 
    
}    

See Also

RasterColor.Reserved

ColorResolutionCommand

Help Version 21.0.2021.11.1
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Imaging, Medical, and Document
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.