Using Director > Vector Shapes and Bitmaps > Controlling bitmap images with Lingo > Editing image objects |  |

Editing image objects

Once you have created an image object, its data can be edited with a variety of Lingo commands designed to manipulate the pixels of the image. You can crop images, draw new pixels on them, copy sections of them, and work with mask and alpha channel information.

To draw a line on an image object:

Use the `draw()` command. You must specify both the locations of each end of the line and the line's color. See `draw()`.

This statement draws a line on the previously created 640 x 480 image object `myImage`, running from 20 pixels inside the top 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()` command. You provide the same information as for the draw command, but Director draws a rectangle instead of a line. See `fill()`.

This 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 `getPixel` or `setPixel`. See `getPixel()` and `setPixel()`.

To copy part or all of an image object into a different image object:

Use `copyPixels()`. This command requires you to specify the image you are copying from, the rectangle to copy the pixels to, and the rectangle to copy the pixels from in the source image. See `copyPixels()`.

This 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 Lingo to modify the pixels you are 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()` command.

This statement performs the same operation as the previous example and tells Lingo 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 `extractAlpha()`. This 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. A reduction in bit depth would otherwise delete the alpha information. See `extractAlpha()`.

This 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. See the categorized section of the Lingo Dictionary for a complete list of these commands.