Imaging Lingo Basics
Table of Contents
CopyPixels
If you think this is fun so far, you haven't seen anything yet. Pixel editing and drawing lines and circles can be useful, but the real power lies in the ability to composite images together and to add effects to them in the process. The most commonly used function in your imaging arsenal is the copyPixels command. CopyPixels takes image data from one object and pastes it into another. In the process, here are some of the things that you can do to the source image as you paste it into its new home…
- Crop it
- Scale it
- Skew it
- Rotate it
- Distort it
- Add ink effects
- Mask it
- Copy without a background
- Blend it
- Dither it
All of this is possible with one command. Let's take a look at how this mighty function works.
i.copyPixels(i2, rect1, rect2)
These are all the required parameters. The above copies the source image (i2) into the destination image(i). It places takes the data from rect2 of image i2 and places it into rect rect1 of itself. Here is an example:
i.copyPixels(myImage, rect(10,10,20,20), rect(50,50,70,70))
This would copy the image data from rect(50,50,70, 70) out of the image stored in myImage and paste it into rect(10,10,20,20) of the main image, i. Not only have you copied over the image, but in the process, you scaled the source image data by half the size.
This easily gives us the ability to "stamp" one image into another. Pretty cool as long as you are just copying rectangular chunks on top of others, but what if you need a little more control? Remember the parameter property list from draw and fill? If so, then the next part will be fairly familiar. Using some predefined properties, you can send more detailed instructions to copyPixels to have it copy only the portions of the image you want, and place them in the new image any way you want.
Advanced CopyPixels
Blend
One of the most basic but also most useful parameters is the ability to blend images. Blending consists of two optional properties you may use.
#blend – This is a value of 0 – 100 with 0 being transparent and 100 being opaque. #blendLevel – This is a value of 0 -255 where 0 is transparent and 255 is opaque.
Why two functions instead of one? The Director score uses a percentage level of 0-100 to define transparency. However, as you learned above with color objects, red, green, blue and alpha vales are based on 0-255. If you want to simulate an alpha blend of 120, then it's easier to use the blendLevel. If you want to mimic a blend of 55% on the stage, then "blend" may be more for you. Both of the following will blend one image onto another at 50%.
i.copyPixels(myImage, i.rect, myImage.rect, [#blend : 50]) i.copyPixels(myImage, i.rect, myImage.rect, [#blendLevel : 127])
This can be very useful for a number of things. Here are a few examples of using blends to get some very nice effects.
- Animated Blend (Example by Dave Mennonah)
- Motion Blur/Trails (Refer to my Devcon Presentation for an example)
- And many other special effects