
116
Chapter 5: Bitmaps
The following statement draws a line on the previously created 640 x 480 image object
myImage
,
running from 20 pixels inside the upper left corner to 20 pixels inside the lower right corner, and
colors it blue:
myImage.draw(20, 20, 620, 460, rgb(0, 0, 255))
To draw a rectangle on an image object:
•
Use the
fill()
method. You provide the same information as for the
draw
method, but
Director draws a rectangle instead of a line.
The following statement draws a red 40 x 40 pixel rectangle near the upper left corner of the
image object
myImage
:
myImage.fill(rect(20, 20, 60, 60), rgb(255, 0, 0))
To determine the color of an individual pixel of an image object or set that pixel’s color:
•
Use the
getPixel
or
setPixel
method.
To copy part or all of an image object into a different image object:
•
Use the
copyPixels()
method, which requires you to specify the image from which you are
copying, the rectangle to which you are copying the pixels, and the rectangle from which to
copy the pixels in the source image.
The following statement copies a 40 x 40 rectangle from the upper left area of the image object
myImage
and puts the pixels into a 40 x 40 rectangle at the lower right of the 300 x 300 pixel
object called
myNewImage
:
myNewImage.copyPixels(myImage, rect(260, 260, 300, 300), rect(0, 0, 40, 40))
When using
copyPixels()
, you can specify optional parameters that tell the script to modify the
pixels you’re copying before drawing them into the destination rectangle. You can apply blends
and inks, change the foreground or background colors, specify masking operations, and more.
You specify these operations by adding a property list at the end of the
copyPixels()
method.
The following statement performs the same operation as the previous example and directs the
script to use the Reverse ink when rendering the pixels into the destination rectangle:
myNewImage.copyPixels(myImage, rect(260, 260, 300, 300), rect(0, 0, 40, 40),
[#ink: #reverse])
To make a new image object from the alpha channel information of a 32-bit image object:
•
Use the
extractAlpha()
method, which can be useful for preserving the alpha channel
information of a 32-bit image object that you plan to reduce to a lower bit depth. Reducing
the bit depth can delete the alpha information.
The following statement creates a new image object called
alphaImage
from the alpha channel
information of the 32-bit image object called
myImage
:
alphaImage = myImage.extractAlpha()
There are many more image-editing operations available through Lingo or JavaScript syntax. For
a complete list, see the Scripting Reference topics in the Director Help Panel.
Summary of Contents for DIRECTOR MX 2004-USING DIRECTOR
Page 1: ...DIRECTOR MX 2004 Using Director...
Page 16: ...16 Chapter 1 Introduction...
Page 82: ...82 Chapter 3 Sprites...
Page 98: ...98 Chapter 4 Animation...
Page 134: ...134 Chapter 5 Bitmaps...
Page 242: ...242 Chapter 10 Sound and Synchronization...
Page 274: ...274 Chapter 11 Using Digital Video...
Page 290: ...290 Chapter 12 Behaviors...
Page 302: ...302 Chapter 13 Navigation and User Interaction...
Page 334: ...334 Chapter 15 The 3D Cast Member 3D Text and 3D Behaviors...
Page 392: ...392 Chapter 16 Working with Models and Model Resources...
Page 418: ...418 Chapter 18 Movies in a Window...
Page 446: ...446 Chapter 22 Managing and Testing Director Projects...