RGBArrayToBrush -- convert pixel array to brush (V5.0)
[id] = RGBArrayToBrush(id, table, width, height[, transtype, invalpha])
This command creates a new brush from the array of RGB pixels specified in table. The table can be regarded as a matrix containing height number of rows where each row has width number of elements. The order of the pixel data in this table must be as follows: Row after row in top-down format, i.e. the table starts with the first row of pixels. Every row must contain exactly width number of pixels, and there must be at least height number of rows. The single pixels must be passed in the RGB format with an optional alpha value. The transtype argument allows you to specify the transparency type the new brush should use. This can be either #NONE for no transparency, #MASK for monochrome transparency, and #ALPHACHANNEL for alpha channel transparency.

The optional argument invalpha can be used to tell RGBArrayToBrush() that all alpha channel values are inverted. This means that a value of 0 means 100% visibility and a value of 255 means invisibility. Normally, it is just the other way round. Due to historical reasons, the Hollywood drawing library uses inverted alpha values, and this why they are also supported by RGBArrayToBrush(), although they are not the default.

If transtype is set to #NONE, the pixels' alpha values are ignored altogether and invalpha does not have any effect either.

Please note that the table that you pass to this function will usually eat lots of memory. Thus, you should set this table to Nil as soon as you no longer need it. Otherwise you will waste huge amounts of memory and it could even happen that your script runs out of memory altogether. So please keep in mind that you should always set pixel array tables to Nil as soon as you are done with them.

To convert a brush to a pixel array, you can use the BrushToRGBArray() function.

identifier for the new brush or Nil for auto id selection
table containing an array of RGB pixels that describe the contents of the new brush; if transtype is set to #MASK or #ALPHACHANNEL you must also specify alpha values in the highest 8 bits
number of elements in each row
number of rows in table
optional: desired transparency setting for brush (defaults to #NONE)
optional: whether to use inverted alpha values (defaults to False which means do not invert alpha values)
optional: identifier of the new brush; will only be returned when you pass Nil as argument 1 (see above)
pixels = {}
col = #BLUE
stp = 256 / 480
For Local y = 0 To 479
   For Local x = 0 To 639 Do pixels[y * 640 + x] = col
   col = col - stp

RGBArrayToBrush(1, pixels, 640, 480)
pixels = Nil    ; IMPORTANT: free memory!
DisplayBrush(1, 0, 0)
The code above creates a color gradient from red to #BLACK and converts it into a brush using RGBArrayToBrush(). Important: Do not forget to set the pixel array to Nil when you no longer need it because otherwise it will stay in memory and pixel arrays will eat huge amounts of memory!

Show TOC