This sets the current colour used when drawing onto this Image. This affects every drawing operation, including drawing other Images onto this one. For example you can use it draw red rectangles, green circles, or blue background images.

See the article on Using Colors for an explanation on the colour values this function can take.

.setColor( :color, alpha=1 )

Sets the 'color' and 'alpha' value used when drawing on to this Image. If the 'alpha' is not provided, then it default to 1 (full alpha).

.setColor( color, alpha=1 ) { ... }

The 'setColor' method can also take a block, where the colour and alpha values are only altered for the lifetime of the block. When the block returns, the colour is set back to what it was before this was called.

.setColor( red, green, blue, alpha=1 )

Sets the drawing colour to the red, green, blue values given. The should be a number between 0 and 255. The alpha value can be optionally provided, and if it is omitted then it will default to 1.0.

.setColor( red, green, blue, alpha=1 ) { ... }

Like the other version of setColor above, which also takes a block, this will only alter the drawing colour and alpha value for the lifetime of this block.

Once the block returns, the drawing colour and alpha are set back to the values they were from before this method was called.

See also

Using Colors - setAlpha - setBlend - getColors - getRed - getGreen - getBlue