Search processing.org:

Reference for Processing (BETA) version 0135+. If you have a previous version, use the reference included with your software. If you see any errors or have any comments, let us know.

Class | PImage

Name

### blend()

Examples

    PImage img = loadImage("rockies.jpg");
    PImage img2 = loadImage("degaul.jpg");
    img.blend(img2, 0, 0, 33, 100, 67, 0, 33, 100, ADD);
    image(img, 0, 0);
    image(img2, 0, 0);

    PImage img = loadImage("rockies.jpg");
    PImage img2 = loadImage("degaul.jpg");
    img.blend(img2, 0, 0, 33, 100, 67, 0, 33, 100, SUBTRACT);
    image(img, 0, 0);
    image(img2, 0, 0);

    PImage img = loadImage("rockies.jpg");
    PImage img2 = loadImage("degaul.jpg");
    img.blend(img2, 0, 0, 33, 100, 67, 0, 33, 100, DARKEST);
    image(img, 0, 0);
    image(img2, 0, 0);

    PImage img = loadImage("rockies.jpg");
    PImage img2 = loadImage("degaul.jpg");
    img.blend(img2, 0, 0, 33, 100, 67, 0, 33, 100, LIGHTEST);
    image(img, 0, 0);
    image(img2, 0, 0);

Description

Blends a region of pixels into the image specified by the img parameter. These copies utilize full alpha channel support and a choice of the following modes to blend the colors of source pixels (A) with the ones of pixels in the destination image (B):
BLEND - linear interpolation of colors: C = A*factor + B
ADD - additive blending with white clip: C = min(A*factor + B, 255)
SUBTRACT - subtractive blending with black clip: C = max(B - A*factor, 0)
DARKEST - only the darkest color succeeds: C = min(A*factor, B)
LIGHTEST - only the lightest color succeeds: C = max(A*factor, B)
All modes use the alpha information (highest byte) of source image pixels as the blending factor. If the source and destination regions are different sizes, the image will be automatically resized to match the destination size. If the srcImg parameter is not used, the display window is used as the source image.
The imageMode() function changes the way the parameters work. For example, a call to imageMode(CORNERS) will change the width and height related parameters to define the x and y values of the opposite corner of the image.

Syntax

    img.blend(x, y, width, height, dx, dy, dwidth, dheight, MODE)
    img.blend(srcImg, x, y, width, height, dx, dy, dwidth, dheight, MODE)

Parameters

img | PImage: any variable of type PImage
x | int: X coordinate of the source's upper left corner
y | int: Y coordinate of the source's upper left corner
width | int: source image width
height | int: source image height
dx | int: X coordinate of the destinations's upper left corner
dy | int: Y coordinate of the destinations's upper left corner
dwidth | int: destination image width
dheight | int: destination image height
srcImg | PImage: a image variable referring to the source image
MODE | Either BLEND, ADD, SUBTRACT, LIGHTEST, DARKEST

Usage | Web & Application
Related | alpha() copy()

Updated on February 09, 2008 04:38:52pm PST