MapObjects Connection

 

Working with colors

Applies to: MapObjects, Working with Colors

Whenever you reference a color in MapObjects, you are really working with a Win32 COLORREF data type. A COLORREF is simply a 32-bit unsigned integer that has the following hexadecimal form:

0x00bbggrr

The low-order byte contains a value for the relative intensity of red; the second byte contains a value for green; and the third byte contains a value for blue. The high-order byte is usually zero. The maximum value for a single byte is 0xFF.

Common Colors Defined by MapObjects

MapObjects defines the following set of common colors:

Constant DecimalHexRGB
moBlack 0 0 (0, 0, 0)
moRed 255 FF (255, 0, 0)
moGreen 65280 FF00 (0, 255, 0)
moBlue 16711680 FF0000 (0, 0, 255)
moMagenta 16711935 FF00FF (255, 0, 255)
moCyan 16776960 FFFF00 (0, 255, 255)
moWhite 16777215 FFFFFF (255, 255, 255)
moLightGray 12632256 C0C0C0 (192, 192, 192)
moDarkGray 4210752 404040 (64, 64, 64)
moGray 8421504 808080 (128, 128, 128)
moPaleYellow 13697023 D0FFFF (255, 255, 208)
moLightYellow 8454143 80FFFF (255, 255, 128)
moYellow 65535 FFFF (255, 255, 0)
moLimeGreen 12639424 C0DCC0 (192, 220, 192)
moTeal 8421440 808040 (64, 128, 128)
moDarkGreen 32768 8000 (0, 128, 0)
moMaroon 128 80 (128, 0, 0)
moPurple 8388736 800080 (128, 0, 128)
moOrange 33023 80FF (255, 128, 0)
moKhaki 7051175 6B97A7 (167, 151, 107)
moOlive 32896 8080 (128, 128, 0)
moBrown 4210816 404080 (128, 64, 64)
moNavy 8404992 804000 (0, 64, 128)

You may also define entirely new colors by specifying different numeric values. The following C macro shows how to create a new color from the red, green, and blue components:

#define RGB(r,g,b)(((unsigned char)
(r)|((unsignedshort)((unsigned char)
(g))<<8))|(((unsigned long)(unsignedchar)
(b))<<16))

For an example in Visual Basic of working with colors and the different methods you can use, see the Color property example in MapObjects.hlp.

Most development environments have a similar utility routine to construct a COLORREF for you.

Working with Palette Colors

Windows provides built-in support for color dithering when a requested color doesn't match any of the colors supported by the display hardware. MapObjects makes use of palettes on systems that require such support. You may still get dithered colors on such systems if you don't specify that you want to match specified colors to the closest color available in the current palette. To specify that you want to use one of the palette colors, set a value of 0x02 in the high order byte of every color that you specify to MapObjects. You can do this by adding 0x02000000 to any colors you use. Doing so should eliminate any unwanted color dithering.