
MediaScript Objects and Methods 139
•
•
•
•
setPixel()
Sets the color of one pixel to the chosen color value. This works in both RGB and CMYK
color spaces.
Syntax
<objectname>.setPixel(
[x @ <"pixel">]
[y @ <"pixel">]
[transparency @ 0-255, or true or false]
[color @ <"color">]
[layers @ <"layer list">] // (PSD files only)
);
Parameters:
x and y - required parameters that specify the coordinates of the target pixel. The top-left
corner of an image is represented by the coordinates 0,0.
transparency - this optional parameter sets the alpha channel of the pixel to that value.
Valid values are 0-255. If this parameter is not specified, the alpha channel (if any) of the
original image remains unchanged.
color - this optional parameter specifies the color that will replace the designated pixel.
The default value for color is the image’s foreground color. For more information about
setting an image’s foreground color, see “setColor()” on page 131.
layers - for PSD files, specifies the layers to be affected. The layer numbers begin at 0
(background). For more information see “load()” on page 101
The foreground color may vary with this function, depending on the original Media object.
If the object has a set foreground color, or it is set with the setColor() function, MediaRich
uses the set color. However, if the object has no set foreground color, MediaRich does the
following:
•
For objects with 256 colors or less, MediaRich uses the last color index.
•
For objects with 15-bit or greater resolution (including the CMYK color-space),
MediaRich uses white.
Example
Image = new Media();
FindColor = "0x000000";
MakeColor = "0xff00ff";
Image.load(name @ "image/32bit.psd");
Rows = Image.getWidth();
Columns = Image.getHeight();
for (x = 0; x < Rows; x++)
{
for (y = 0; y < Columns; y++)
{