←Select platform

RasterUserMatchTable Class

Summary

Maintains a predefined table to speed conversion with a user palette when using ColorResolutionCommand.

Syntax

C#
VB
WinRT C#
C++
public class RasterUserMatchTable 
Public Class RasterUserMatchTable  
public sealed class RasterUserMatchTable  
function Leadtools.ImageProcessing.RasterUserMatchTable() 
public ref class RasterUserMatchTable  

Remarks

Use the RasterUserMatchTable class to create a predefined table to speed conversion with a user palette when using ColorResolutionCommand.

You should use the following sequence:

  1. Create a new instance of the RasterUserMatchTable class
  2. Call the RasterUserMatchTable.Create method to create the table.
  3. Call the RasterUserMatchTable.Use method to make this the current table. (Having this as a separate method allows you to save tables in files and get the one you need, without creating it again.)
  4. Run ColorResolutionCommand with ColorResolutionCommandPaletteFlags.UsePalette or ColorResolutionCommandPaletteFlags.FastMatch set in the ColorResolutionCommand.PaletteFlags property.
  5. Call the Unuse method when the table is no longer needed.

The completed table is a 32K array of integers. On a 32-bit system, it occupies 128K bytes of memory. Creation of the table is a slow, memory-intensive process that is useful only if you are using your own palette more than once. For example, you may want to create the table once, save it to a file, and ship that file with your application.

Example

This example changes the color resolution of a bitmap, using a user-defined palette and a match table for fast color matching.

C#
VB
Silverlight C#
Silverlight VB
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.ImageProcessing; 
using Leadtools.ImageProcessing.Core; 
using LeadtoolsExamples.Common; 
 
public void RasterUserMatchTableExample() 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   string srcFileName = Path.Combine(ImagesPath.Path, "Image1.cmp"); 
   string destFileName = Path.Combine(ImagesPath.Path, "RasterUserMatchTable.bmp"); 
 
   // Load the image from disk 
   RasterImage image = codecs.Load(srcFileName); 
 
   // 64-color rainbow palette 
   RasterColor[] colors = 
   { 
      new RasterColor(0, 0, 0), new RasterColor(0, 0, 85), new RasterColor(0, 0, 170), new RasterColor(0, 0, 255), 
      new RasterColor(85, 0, 0), new RasterColor(85, 0, 85), new RasterColor(85, 0, 170), new RasterColor(85, 0, 255), 
      new RasterColor(170, 0, 0), new RasterColor(170, 0, 85), new RasterColor(170, 0, 170), new RasterColor(170, 0, 255), 
      new RasterColor(255, 0, 0), new RasterColor(255, 0, 85), new RasterColor(255, 0, 170), new RasterColor(255, 0, 255), 
      new RasterColor(0, 85, 0), new RasterColor(0, 85, 85), new RasterColor(0, 85, 170), new RasterColor(0, 85, 255), 
      new RasterColor(85, 85, 0), new RasterColor(85, 85, 85), new RasterColor(85, 85, 170), new RasterColor(85, 85, 255), 
      new RasterColor(170, 85, 0), new RasterColor(170, 85, 85), new RasterColor(170, 85, 170), new RasterColor(170, 85, 255), 
      new RasterColor(255, 85, 0), new RasterColor(255, 85, 85), new RasterColor(255, 85, 170), new RasterColor(255, 85, 255), 
      new RasterColor(0, 170, 0), new RasterColor(0, 170, 85), new RasterColor(0, 170, 170), new RasterColor(0, 170, 255), 
      new RasterColor(85, 170, 0), new RasterColor(85, 170, 85), new RasterColor(85, 170, 170), new RasterColor(85, 170, 255), 
      new RasterColor(170, 170, 0), new RasterColor(170, 170, 85), new RasterColor(170, 170, 170), new RasterColor(170, 170, 255), 
      new RasterColor(255, 170, 0), new RasterColor(255, 170, 85), new RasterColor(255, 170, 170), new RasterColor(255, 170, 255), 
      new RasterColor(0, 255, 0), new RasterColor(0, 255, 85), new RasterColor(0, 255, 170), new RasterColor(0, 255, 255), 
      new RasterColor(85, 255, 0), new RasterColor(85, 255, 85), new RasterColor(85, 255, 170), new RasterColor(85, 255, 255), 
      new RasterColor(170, 255, 0), new RasterColor(170, 255, 85), new RasterColor(170, 255, 170), new RasterColor(170, 255, 255), 
      new RasterColor(255, 255, 0), new RasterColor(255, 255, 85), new RasterColor(255, 255, 170), new RasterColor(255, 255, 255) 
   }; 
 
   // Create and set the user match table 
   RasterUserMatchTable userMatchTable = new RasterUserMatchTable(); 
   userMatchTable.Create(colors); 
   userMatchTable.Use(); 
 
   // Change the color resolution using the new palette. Note that the user match table 
   // is makes your code faster only if you use it more than once. It is included here only  
   // to show how it can be coded. 
 
   ColorResolutionCommand command = new ColorResolutionCommand( 
      ColorResolutionCommandMode.InPlace, 
      8, 
      RasterByteOrder.Rgb, 
      RasterDitheringMethod.FloydStein, 
      ColorResolutionCommandPaletteFlags.UsePalette | ColorResolutionCommandPaletteFlags.FastMatch, 
      colors); 
   command.Run(image); 
 
   // Free the user match table when it is no longer needed 
   userMatchTable.Unuse(); 
 
   // Save the image back to disk 
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 8); 
 
   // Clean up 
   image.Dispose(); 
   codecs.Dispose(); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
Imports Leadtools.ImageProcessing.Core 
 
Public Sub RasterUserMatchTableExample() 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   Dim srcFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "Image1.cmp") 
   Dim destFileName As String = Path.Combine(LEAD_VARS.ImagesDir, "RasterUserMatchTable.bmp") 
 
   ' Load the image from disk 
   Dim image As RasterImage = codecs.Load(srcFileName) 
 
   ' 64-color rainbow palette 
   Dim colors As RasterColor() = {New RasterColor(0, 0, 0), New RasterColor(0, 0, 85), New RasterColor(0, 0, 170), 
                                  New RasterColor(0, 0, 255), New RasterColor(85, 0, 0), New RasterColor(85, 0, 85), 
                                  New RasterColor(85, 0, 170), New RasterColor(85, 0, 255), New RasterColor(170, 0, 0), 
                                  New RasterColor(170, 0, 85), New RasterColor(170, 0, 170), New RasterColor(170, 0, 255), 
                                  New RasterColor(255, 0, 0), New RasterColor(255, 0, 85), New RasterColor(255, 0, 170), 
                                  New RasterColor(255, 0, 255), New RasterColor(0, 85, 0), New RasterColor(0, 85, 85), 
                                  New RasterColor(0, 85, 170), New RasterColor(0, 85, 255), New RasterColor(85, 85, 0), 
                                  New RasterColor(85, 85, 85), New RasterColor(85, 85, 170), New RasterColor(85, 85, 255), 
                                  New RasterColor(170, 85, 0), New RasterColor(170, 85, 85), New RasterColor(170, 85, 170), 
                                  New RasterColor(170, 85, 255), New RasterColor(255, 85, 0), New RasterColor(255, 85, 85), 
                                  New RasterColor(255, 85, 170), New RasterColor(255, 85, 255), New RasterColor(0, 170, 0), 
                                  New RasterColor(0, 170, 85), New RasterColor(0, 170, 170), New RasterColor(0, 170, 255), 
                                  New RasterColor(85, 170, 0), New RasterColor(85, 170, 85), New RasterColor(85, 170, 170), 
                                  New RasterColor(85, 170, 255), New RasterColor(170, 170, 0), New RasterColor(170, 170, 85), 
                                  New RasterColor(170, 170, 170), New RasterColor(170, 170, 255), New RasterColor(255, 170, 0), 
                                  New RasterColor(255, 170, 85), New RasterColor(255, 170, 170), New RasterColor(255, 170, 255), 
                                  New RasterColor(0, 255, 0), New RasterColor(0, 255, 85), New RasterColor(0, 255, 170), 
                                  New RasterColor(0, 255, 255), New RasterColor(85, 255, 0), New RasterColor(85, 255, 85), 
                                  New RasterColor(85, 255, 170), New RasterColor(85, 255, 255), New RasterColor(170, 255, 0), 
                                  New RasterColor(170, 255, 85), New RasterColor(170, 255, 170), New RasterColor(170, 255, 255), 
                                  New RasterColor(255, 255, 0), New RasterColor(255, 255, 85), New RasterColor(255, 255, 170), 
                                  New RasterColor(255, 255, 255)} 
 
   ' Create and set the user match table 
   Dim userMatchTable As RasterUserMatchTable = New RasterUserMatchTable() 
   userMatchTable.Create(colors) 
   userMatchTable.Use() 
 
   ' Change the color resolution using the new palette. Note that the user match table 
   ' is makes your code faster only if you use it more than once. It is included here only  
   ' to show how it can be coded. 
 
   Dim command As ColorResolutionCommand = New ColorResolutionCommand( 
                                           ColorResolutionCommandMode.InPlace, 8, RasterByteOrder.Rgb, 
                                           RasterDitheringMethod.FloydStein, 
                                           ColorResolutionCommandPaletteFlags.UsePalette Or 
                                           ColorResolutionCommandPaletteFlags.FastMatch, colors) 
   command.Run(image) 
 
   ' Free the user match table when it is no longer needed 
   userMatchTable.Unuse() 
 
   ' Save the image back to disk 
   codecs.Save(image, destFileName, RasterImageFormat.Bmp, 8) 
 
   ' Clean up 
   image.Dispose() 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const ImagesDir As String = "C:\Users\Public\Documents\LEADTOOLS Images" 
End Class 
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Examples; 
using Leadtools.ImageProcessing; 
 
public void RasterUserMatchTableExample(RasterImage image, Stream destStream) 
{ 
   RasterCodecs codecs = new RasterCodecs(); 
 
   // 64-color rainbow palette 
   RasterColor[] colors = 
   { 
      new RasterColor(0, 0, 0), new RasterColor(0, 0, 85), new RasterColor(0, 0, 170), new RasterColor(0, 0, 255), 
      new RasterColor(85, 0, 0), new RasterColor(85, 0, 85), new RasterColor(85, 0, 170), new RasterColor(85, 0, 255), 
      new RasterColor(170, 0, 0), new RasterColor(170, 0, 85), new RasterColor(170, 0, 170), new RasterColor(170, 0, 255), 
      new RasterColor(255, 0, 0), new RasterColor(255, 0, 85), new RasterColor(255, 0, 170), new RasterColor(255, 0, 255), 
      new RasterColor(0, 85, 0), new RasterColor(0, 85, 85), new RasterColor(0, 85, 170), new RasterColor(0, 85, 255), 
      new RasterColor(85, 85, 0), new RasterColor(85, 85, 85), new RasterColor(85, 85, 170), new RasterColor(85, 85, 255), 
      new RasterColor(170, 85, 0), new RasterColor(170, 85, 85), new RasterColor(170, 85, 170), new RasterColor(170, 85, 255), 
      new RasterColor(255, 85, 0), new RasterColor(255, 85, 85), new RasterColor(255, 85, 170), new RasterColor(255, 85, 255), 
      new RasterColor(0, 170, 0), new RasterColor(0, 170, 85), new RasterColor(0, 170, 170), new RasterColor(0, 170, 255), 
      new RasterColor(85, 170, 0), new RasterColor(85, 170, 85), new RasterColor(85, 170, 170), new RasterColor(85, 170, 255), 
      new RasterColor(170, 170, 0), new RasterColor(170, 170, 85), new RasterColor(170, 170, 170), new RasterColor(170, 170, 255), 
      new RasterColor(255, 170, 0), new RasterColor(255, 170, 85), new RasterColor(255, 170, 170), new RasterColor(255, 170, 255), 
      new RasterColor(0, 255, 0), new RasterColor(0, 255, 85), new RasterColor(0, 255, 170), new RasterColor(0, 255, 255), 
      new RasterColor(85, 255, 0), new RasterColor(85, 255, 85), new RasterColor(85, 255, 170), new RasterColor(85, 255, 255), 
      new RasterColor(170, 255, 0), new RasterColor(170, 255, 85), new RasterColor(170, 255, 170), new RasterColor(170, 255, 255), 
      new RasterColor(255, 255, 0), new RasterColor(255, 255, 85), new RasterColor(255, 255, 170), new RasterColor(255, 255, 255) 
   }; 
 
   // Create and set the user match table 
   RasterUserMatchTable userMatchTable = new RasterUserMatchTable(); 
   userMatchTable.Create(colors); 
   userMatchTable.Use(); 
 
   // Change the color resolution using the new palette. Note that the user match table 
   // is makes your code faster only if you use it more than once. It is included here only  
   // to show how it can be coded. 
 
   ColorResolutionCommand command = new ColorResolutionCommand( 
      ColorResolutionCommandMode.InPlace, 
      8, 
      RasterByteOrder.Rgb, 
      RasterDitheringMethod.FloydStein, 
      ColorResolutionCommandPaletteFlags.UsePalette | ColorResolutionCommandPaletteFlags.FastMatch, 
      colors); 
   command.Run(image); 
 
   // Free the user match table when it is no longer needed 
   userMatchTable.Unuse(); 
 
   // Save the image back to disk 
   codecs.Save(image, destStream, RasterImageFormat.Bmp, 8); 
 
   // Clean up 
   image.Dispose(); 
} 
Imports Leadtools 
Imports Leadtools.Codecs 
Imports Leadtools.ImageProcessing 
 
Public Sub RasterUserMatchTableExample(ByVal image As RasterImage, ByVal destStream As Stream) 
   Dim codecs As RasterCodecs = New RasterCodecs() 
 
   ' 64-color rainbow palette 
   Dim colors As RasterColor() = {New RasterColor(0, 0, 0), 
                                  New RasterColor(0, 0, 85), 
                                  New RasterColor(0, 0, 170), 
                                  New RasterColor(0, 0, 255), 
                                  New RasterColor(85, 0, 0), 
                                  New RasterColor(85, 0, 85), 
                                  New RasterColor(85, 0, 170), 
                                  New _ 
         RasterColor(85, 0, 255), New RasterColor(170, 0, 0), New RasterColor(170, 0, 85), New RasterColor(170, 0, 170), New RasterColor(170, 0, 255), New RasterColor(255, 0, 0), New RasterColor(255, 0, 85), New RasterColor(255, 0, 170), New _ 
         RasterColor(255, 0, 255), New RasterColor(0, 85, 0), New RasterColor(0, 85, 85), New RasterColor(0, 85, 170), New RasterColor(0, 85, 255), New RasterColor(85, 85, 0), New RasterColor(85, 85, 85), New RasterColor(85, 85, 170), New _ 
         RasterColor(85, 85, 255), New RasterColor(170, 85, 0), New RasterColor(170, 85, 85), New RasterColor(170, 85, 170), New RasterColor(170, 85, 255), New RasterColor(255, 85, 0), New RasterColor(255, 85, 85), New RasterColor(255, 85, 170), 
         New RasterColor(255, 85, 255), New RasterColor(0, 170, 0), New RasterColor(0, 170, 85), New RasterColor(0, 170, 170), New RasterColor(0, 170, 255), New RasterColor(85, 170, 0), New RasterColor(85, 170, 85), New RasterColor(85, 170, 170), 
         New RasterColor(85, 170, 255), New RasterColor(170, 170, 0), New RasterColor(170, 170, 85), New RasterColor(170, 170, 170), New RasterColor(170, 170, 255), New RasterColor(255, 170, 0), New RasterColor(255, 170, 85), New RasterColor(255, 
         170, 170), New RasterColor(255, 170, 255), New RasterColor(0, 255, 0), New RasterColor(0, 255, 85), New RasterColor(0, 255, 170), New RasterColor(0, 255, 255), New RasterColor(85, 255, 0), New RasterColor(85, 255, 85), New _ 
         RasterColor(85, 255, 170), New RasterColor(85, 255, 255), New RasterColor(170, 255, 0), New RasterColor(170, 255, 85), New RasterColor(170, 255, 170), New RasterColor(170, 255, 255), New RasterColor(255, 255, 0), New RasterColor(255, 
         255, 85), New RasterColor(255, 255, 170), New RasterColor(255, 255, 255)} 
 
   ' Create and set the user match table 
   Dim userMatchTable As RasterUserMatchTable = New RasterUserMatchTable() 
   userMatchTable.Create(colors) 
   userMatchTable.Use() 
 
   ' Change the color resolution using the new palette. Note that the user match table 
   ' is makes your code faster only if you use it more than once. It is included here only  
   ' to show how it can be coded. 
 
   Dim command As ColorResolutionCommand = New ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 8, RasterByteOrder.Rgb, RasterDitheringMethod.FloydStein, ColorResolutionCommandPaletteFlags.UsePalette Or 
         ColorResolutionCommandPaletteFlags.FastMatch, colors) 
   command.Run(image) 
 
   ' Free the user match table when it is no longer needed 
   userMatchTable.Unuse() 
 
   ' Save the image back to disk 
   codecs.Save(image, destStream, RasterImageFormat.Bmp, 8) 
 
   ' Clean up 
   image.Dispose() 
End Sub 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools Assembly