Py5Image.mask()

Masks part of an image from displaying by loading another image and using it as an alpha channel.

Examples

example picture for mask()
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
def setup():
    global photo
    global mask_image
    photo = py5.load_image("test.jpg")
    mask_image = py5.load_image("mask.jpg")
    photo.mask(mask_image)


def draw():
    py5.image(photo, 0, 0)
    py5.image(photo, py5.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.

Underlying Java method: PImage.mask

Syntax

mask(img: Py5Image, /) -> None
mask(mask_array: NDArray[(Any,), Int], /) -> None

Parameters

  • img: Py5Image - image to use as the mask

  • mask_array: NDArray[(Any,), Int] - array of integers used as the alpha channel, needs to be the same length as the image’s pixel array.

Updated on September 11, 2021 16:51:34pm UTC