- Processing
- p5.js
- Processing.py
- Processing for Android
- Processing for Pi

- Processing Foundation

This reference is for Processing 3.0+. If you have a previous version, use the reference included with your software in the Help menu. If you see any errors or have suggestions, please let us know. If you prefer a more technical reference, visit the Processing Core Javadoc and Libraries Javadoc.

Class | PImage
Name | ### mask()
Examples |
    PImage photo, maskImage;

    void setup() {
      size(100, 100);
      photo = loadImage("test.jpg");
      maskImage = loadImage("mask.jpg");
      photo.mask(maskImage);
    }

    void draw() {
      image(photo, 0, 0);
      image(photo, width/4, 0);
    }
Description | Masks part of an image from displaying by loading another image and using it as an alpha channel. This mask image should only contain grayscale data, but only the blue color channel is used. The mask image needs to be the same size as the image to which it is applied. In addition to using a mask image, an integer array containing the alpha channel data can be specified directly. This method is useful for creating dynamically generated alpha masks. This array must be of the same length as the target image's pixels array and should contain only grayscale data of values between 0-255.
Syntax |
    pimg.mask(maskArray)
    pimg.mask(img)
Parameters |
pimg | PImage: any object of type PImage
maskArray | int[]: array of integers used as the alpha channel, needs to be the same length as the image's pixel array.
img | PImage: image to use as the mask
Returns | void

Updated on January 1, 2021 03:38:09am EST
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.