Hi, I want to capture and store the RGB values from an area of pixels anywhere on the screen (- not from a preloaded image - but of the screen) and that’s where I’m stumbling. As all the examples I’ve seen, first load an image for processing, whereas I would like to capture an area of the screen itself. This will allow me to save various colour sequences and play them back for a RGB (WS2812B) lamp that I have built.
Are there any kind souls who could helpfully point me in the right direction? Many thanks in advance. Chris.
// Get Colors
// v1.0.0
// GLV 2022-04-02
PImage getImg;
void setup()
{
size(500, 500);
background(128);
noStroke();
// 8 random RGB colors
for(int i= 0; i< 200; i++)
{
fill(int(random(2))*255, int(random(2))*255, int(random(2))*255);
circle(random(width), random(height), 50);
}
}
void draw()
{
// Get an area 50x50 from sketch window and store in a PImage
getImg = get(mouseX, mouseY, 50, 50);
//Display it
image(getImg, width-50, 0);
// Get a single pixel from the 50x50 PImage
int getPixelColor1 = getImg.get(0, 0);
println("1:", hex(getPixelColor1));
// Get a single pixel from the sketch window
int getPixelColor2 = get(mouseX, mouseY);
println("2:", mouseX, mouseY, hex(getPixelColor1));
}
Glv, thank you for your kind example and references. My stumbling block is I want to be able to sample the desktop or another window not necessarily created by processing (sorry I said screen which was I think, a misleading description!). In your example I tried making the background transparent using background(128,255); in the hope of setting the alpha of the window transparent (so I could sample anything beneath it?) - but it’s still a solid gray. I also tried using tint(255,255); but that didn’t make the window transparent either. In the meantime I’ll follow up the references you gave, if you have any other pointers - all gratefully received