Reads the color of any pixel or grabs a section of an image. If no parameters are specified, the entire image is returned. Use the x and y parameters to get the value of one pixel. Get a section of the display window by specifying an additional width and height parameter.
(int x, int y)
| 579 | * @see PApplet#copy(PImage, int, int, int, int, int, int, int, int) |
| 580 | */ |
| 581 | public int get(int x, int y) { |
| 582 | if ((x < 0) || (y < 0) || (x >= pixelWidth) || (y >= pixelHeight)) return 0; |
| 583 | |
| 584 | return switch (format) { |
| 585 | case RGB -> pixels[y * pixelWidth + x] | 0xff000000; |
| 586 | case ARGB -> pixels[y * pixelWidth + x]; |
| 587 | case ALPHA -> (pixels[y * pixelWidth + x] << 24) | 0xffffff; |
| 588 | default -> 0; |
| 589 | }; |
| 590 | } |
| 591 | |
| 592 | |
| 593 | /** |