5

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.

Charlie Wallace
  • 1,810
  • 1
  • 15
  • 17
Oliver Goossens
  • 1,903
  • 3
  • 20
  • 26
  • What about the css `clip` property? `img { position: absolute; clip: rect(0px,60px,200px,0px); }` – mwilson Oct 04 '17 at 21:16

2 Answers2

6

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.

Oliver Goossens
  • 1,903
  • 3
  • 20
  • 26
0

You can also use copy() from p5. P5 copy() reference

Drunken Janna
  • 146
  • 1
  • 10