Handling Palette Changes

Whenever you paint an image to a device of 256 colors or less, the current system palette is used. This topic describes how to ensure that the current system palette is the one you want to use.

First, consider that LEADTOOLS gives you the following two choices for painting to a device of 256 colors or less:

Generally, the following order of execution ensures that the current system palette is the one you want to use:

  1. Set the display mode to turn on or turn off the fixed palette when painting all images. The following code turns on the LEAD fixed palette: PaintDisplayMode = FixedPalette; The following code turns off the LEAD fixed palette: PaintDisplayMode = None;
  2. Create the paint palette. The RasterImagePainter.GetPaintPalette method returns a palette that you want to use. If the fixed palette is turned on, this is always the fixed palette. Otherwise it is the best available palette for the specified image. The following code shows the variable declarations and the method call. (The scope of the variables is application dependent; they are shown all together here for simplicity.)
    string srcFileName = @"d:\lt16\Images\eye.gif"; 
    RasterImage srcImage = codecs.Load(srcFileName); 
    Graphics g = this.CreateGraphics(); 
    System.Drawing.Imaging.ColorPalette palPaint = srcImage.GetPaintPalette(g); 
  3. Call one of the LEADTOOLS painting methods. The following example uses Rectangle variables that are defined elsewhere, as described in the comments:
    Rectangle dstRect = new Rectangle(0, 0, srcImage.Width, srcImage.Height); 
    RasterPaintProperties props = RasterPaintProperties.Default; 
    srcImage.Paint(g, Rectangle.Empty, dstRect, props); 

Please note that if you are painting a 16-bit grayscale image to a 24-bit device, you must call RasterImagePainter.GetPaintPalette before you call RasterImagePainter.Paint.

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.