GraphicImage Template
drawPixels()
Set the colour for specific pixels within an image
Syntax
GraphicImage = rb.GraphicImage.drawPixels(pointArray, defaultColour)
Parameters
The 'drawPixels' method takes 2 parameters:
Name | Type/Value | Range/Length | Description | pointArray | array of struct Points | see definition | Required.
'set' one or more pixels within an image
| defaultColour | number | | Optional.
An optional colour to set for pixels in the array. If an entry in the pixel array does *not* specify a color (c:)
then this default colour is used. If there is no default specified and the pixel entry does not specify a colour
then the default colour is taken to be zero (0) : colour index 0 for a palette images, or black for a
true colour image.
|
Results
The 'drawPixels' method returns GraphicImage:
Type/Value | Range/Length | Description |
GraphicImage |
  |
Returns a reference to 'this' if the operation succeeds, otherwise throws an exception.
|
Remarks 'draw' one or more pixels at [x,y] co-ordinates within the image. The target pixels are
specified in an array and so a single call can draw many pixels. The colour with which pixels are drawn can be determined in one of two ways: - On a pixel-by-pixel basis within the array by specifying a colour attribute 'c' on each pixel
- By alternatively specifying a 'defaultColour' second parameter
These two colour specifying methods are not mutually exclusive so you can specify a default colour and then
over-ride that on a pixel by pixel basis as needed. If a pixel does not have a specifically defined colour and there is no defaultColour parameter then :
for true-colour (the default) pixels are set to black ; for palette based, to the colour index
'0' within the palette (first colour specified). Example
// Create an empty 100x100 pixel image
var img = (new GraphicImage).create(100,100);
// Draw the pixels {0,0},{1,1},{2,2} to red and the pixel at {3,3} to blue
var red = img.colourAlloc(255,0,0);
var blue = img.colourAlloc( 0,0,255);
var pixels = [
{x:0, y:1},
{x:1, y:1},
{x:2, y:2},
{x:3, y:3, c:blue}
];
img.drawPixels(pixels,red);
|