PalettesThe image contained in the ShotGraph's imagespace is always a true color image. However, there are some cases when you need to get the image with limited number of colors (GIF or WBMP image). GIF file can have up to 256 colors, WBMP file is a B/W image. Therefore, in such cases an image needs to be converted from true color form to paletted one.
The easiest way to get paletted image is to define several indexed colors using the SetColor method and then use only those colors for building image. In this case you are limited to use only predefined shapes (line, ellipse and others) and text for creating your image context.
For example, you created image with 8 indexed colors and use the simple lines, rectangles and non-antialiased text to draw the image content, and then call the GifImage method to create a gif file. In such case ShotGraph makes this conversion automatically when you call the GifImage function. In the process of conversion, all color indexes earlier defined by SetColor will be mapped into result gif image palette entries.
However, in many situations the number of individual colors in an image is very high and real colors of the image are unknown or don't match the indexed colors defined by you. Such situation can occur in the following cases:
In this situation use either BuildPalette or ApplyPalette method to convert your true color image to paletted one.
This method recalculates palette entries from image data and alter image in accordance with them. As a rule, the method is called once just before GifImage (or similar method creating a paletted image). For example, if you want to convert Jpeg image (true color) to Gif format, then after reading jpeg image into imagespace you need to call the BuildPalette once just before GifImage method.
This method alters image data in imagespace in accordance with specified colors. The colors should be predefined by SetColor calls. These palette entries are not altered. Using this feature you can convert your image to BW and, in common case, to any bi-, three-, four- etc. color image with predefined colors. As a rule, the method is called once just before GifImage (or similar method creating a paletted image).
Palette sizePalette size is the number of indexed colors in the image. The maximum size of palette is 256. The minimum size of palette is 2. In the consequence of specific limitations of GIF file format, the palette size must be a power of 2. So possible values are 2, 4, 8, 16, 32, 64, 128, 256.
Palette indexPalette index is zero based. For example, if you creates the image with 64 colors, the palette index mush be between and including 0 and 63. To define the palette entry with specific color use the SetColor function.
ExamplesThe following example shows the effect of different methods (BuildPalette, ApplyPalette). In case of BuildPalette we use the palette size 16 (to make the changes more visible).
See tooCreateImage, SetColor, BuildPalette, ApplyPalette functions in the Methods & properties.
© 1998-2001 Mikhail Tchikalov
Email to contact: firstname.lastname@example.org