Search code examples
screenshotprocessingprocessing.js

How to capture a specific area on the sketch in Processing


I want to take a screenshot of a specific area in the sketch (in processing). With save(); and saveFrame(); references I can't do it because they capture the whole area, but i just need a smaller specific are to capture. How to do it properly?


Solution

  • Check the Processing reference. There's a function called get that may be called on PImages or the drawing screen itself. You don't mention whether you want to capture some weird shape or a rectangle, so I'll assume a standard rectangle. According to its documentation, what you want is:

    Syntax: get(x, y, w, h)

    Parameters:

    • x int: x-coordinate of the pixel
    • y int: y-coordinate of the pixel
    • w int: width of pixel rectangle to get
    • h int: height of pixel rectangle to get