Image Object Agents

 

An Image Object is created by using the Image() constructor. As with most of the Object Agents created from LightWave items, you can create these Objects by either supplying a specific name of an image loaded into LightWave (no extension or path information is necessary), or pass no arguments and create the Object from the first image loaded.

image = Image();      // Create an image object
                   // from the first image loaded.

image = Image(2);      // Create an image object
                     // from the second image loaded.

image = Image("imageName");      // Create an image object
                               // by name.

Besides those Data Methods and Methods common to all LightWave items, the following are specific to Image Object Agents.

Note: Remember that not all of the common Data Members and Methods apply to Image Objects.

Data Members

name
name returns a string representing the name as it appears on the interface.

isColor
isColor returns a Boolean value indicating a color or black and white image.

width
width returns a value indicating the width of the image in pixels.

height
height returns a value indicating the height of the image in pixels.

hasAlpha
hasAlpha is a Boolean flag that indicates whether or not the image contains any Alpha image data. If this flag is true, then the Alpha data can be accessed using the alpha() and alphaSpot() methods.

Methods

filename(frame)
filename(frame) returns the path information for the Image Object Agent at the frame given.

luma(x, y)
luma(x, y) returns the grayscale value for the pixel located at the given (x,y) integer values.

rgb(x,y)
rgb(x, y) returns the RGB value for the pixel located at the given (x,y) integer values.

rgbspot(x,y)
No idea what this is supposed to do...

alpha(x, y)
alpha(x, y) will return the Alpha value for a pixel, given an integer (x,y) position within the image. Alpha-channel data contains only one numeric value for each triplet RGB value.

alphaspot(x, y)
alpha(x, y) will return the Alpha value for a pixel, given an integer (x,y) position within the image. Alpha-channel data contains only one numeric value for each triplet RGB value.

replace(filename)
.replace will replace the image in the current image agent with the image in the filename. This returns an error if the filename is nil, or clears the image completely if the filename is a valid string, but the file does not exist.

Example:

myimage=Image();
myname=getfile("Hello");
myimage.replace(myname);

General Commands

loadimage
loadimage loads an image from a filename and returns the image object agent of that image or 'nil', if the image does not exist.
Example:
myimage=loadimage("c:\images\myimage.tga");

clearimage
clearimage when given an image object agent, clears that image from the scene.
Example:
myimage=loadimage("c:\images\myimage.tga");
clearimage(myimage);

replaceimage
replaceimage when given an image object agent, replaces that image from the scene with the image from the filename.
Example:
myimage=loadimage("c:\images\myimage.tga");
replaceimage(myimage);

Examples:

This example creates an Image Object from the first image loaded, and displays some of its properties.

@version 2.2
@warnings
@script generic
@name ImageObjectAgentTest

generic
{
    // Create an ImageObjectAgent from the first
    // image loaded.
    image = Image() || error("No images loaded!");

     // Display the data members.
    info("Name: ", image.name);
    info("Width: ", image.width);
    info("Height: ", image.height);
    info("isColor: ", image.isColor);
    info("hasAlpha: ", image.hasAlpha);
}