How to find all pixels within a PShape?

Hi,

I need to find the position or at least the color of all pixels within a PShape. How could I achieve that? My final goal is to find the average color within a PShape. I know there must be a trivial way of doing this, that is what happen on draw when you define a fill color after all, but after long search I still have no clue, or at least could not think of an efficient way to achieve this.

If anyone has an idea, would love to hear it! Thanks.

Tagged:

Answers

    • Create a PGraphics.
    • Draw your PShape on it. The pixels not drawn are transparent.
    • Iterate over the pixels[] array, excluding the transparent pixels.
Sign In or Register to comment.