P5.js - Is there a way to cut out an image area?

Viewed 5026

Is there a way to "cut out" a piece of image and use it with the P5.js library?

Example: Lets say I have a image of the size 100x100 but need to get a 10x10 pixel cutout that starts at pixel 50,50

10x10px cutout from an 100x100px image from 50,50px

I want to take the resulting 10x10 image and place it anywhere with image(result, X, Y, 10, 10).

Note: The only thing I could find online similar to this was using mask() but the result is not what I need.

2 Answers

After a deeper look inside, and help from fellow P5ers I figured out that the solution is:

The GET() method from P5.js

https://p5js.org/reference/#/p5/get

The get() method can be used as needed: get(startX, startY, width, height) and returns and image that can be saved or used as needed.

Related