As well as the location of an object you want drawn you also have to specify a Color for it. There are many ways of describing a color. You can use a Color Name and this works well for many common colors. However for more precise control over colors you should use RGB Colors.


ImageGlue Color Names    

You can specify colors using Color Names. You can use any of the following.

  • "black"
  • "white"
  • "yellow"
  • "magenta"
  • "red"
  • "cyan"
  • "green"
  • "blue"
  • "gray"
  • "lightgray"
  • "darkgray"

If you use a blank name (i.e. "") the color is assumed to be white.


RGB Color Strings    

An RGB color specifies the intensity of the Red, Green and Blue components of a color. Imagine it as a set of three overlapping colored lights. Any color can be created using a combination of these lights.

We specify the intensity as a percentage. 0% indicates that the light is off, 100% that it is fully on. So:

  • If you want a bright red you should have the red light on and the green and blue off (color = 100,0,0).
  • If you want a blue you should have the blue on and the others off (color = 0,0,100).
  • If you want black you should have all off (color = 0,0,0)
  • If you want white you should have all on (color=100,100,100).

Some graphics packages specify color intensities as decimal numbers between 0 and 255 or as hexadecimal numbers between 00 and FF. You can use both these methods. For decimal numbers you must preceed the number by 0d and for hexadecimal by 0x. So:

  • If you want a bright red you could specify 0d255,0d0,0d0
  • If you want a bright blue you could specify 0x00,0x00,0xFF
  • If you want black you could specify 0x00,0x00,0x00
  • If you want cyan you could specify 0d00,0d255,0d255

When working with HTML you may want to specify a color using an RGB Hex Code as used in HTML. So:

  • If you want a bright red you could specify #FF0000
  • If you want a bright blue you could specify #0000FF
  • If you want black you could specify #000000
  • If you want cyan you could specify #00FFFF


RGBA Color Strings    

An RGBA color is exactly the same as an RGB color but includes a fourth component Alpha, which is a measure of transparency. The alpha value is optional and defaults to 100% opaque (i.e. not transparent). You cannot generally draw with an RGBA Color but you may wish to determine the color and opacity of a point on a canvas.

You can use any of the standard methods to specify an RGBA color. So the following are all valid blues at 50% alpha:

  • 0,0,100,50
  • 0d0,0d0,0d255,0d127
  • 0x00,0x00,0xFF,0x7F
  • #0000FF7F

Alpha is described more fully in the channels section.


Relationships between Color Names and RGB Colors    

Each of the Color names corresponds to an RGB color. The particular RGB color is chosen to look correct rather than to fit in with the definitions of RGB color space.

For example the green in the image above is 100% green and 0% anything else. However this color is not what most people would regard as a typical green. The RGB color for the 'green' Color Name looks more like the kind of green you might expect.

What this means is that if you want precise control over the color components of your colors you must explicitly use RGB colors.