Raspberry pi color picker problem [Solved]

Hello i have problem which picking a color.
On pc everything work ok. When i am using raspberry i sometimes have good color and more often black (Independence what color i choose, quite obvious).

code responsible for color picking:

pix.grabScreen(mouseX, mouseY, 1, 1);
unsigned char *pixels=pix.getPixels();
ofColor temp;
temp = pix.getPixelsRef().getColor(0, 0);

I am grabbing small part of screen near mouse position. I run it in :mousePressed

Maybe somone was trying do something similar?
Maybe should I grab full screen? If i would do that i will “kill” my raspberry probably…
Thanks for any help:)

Could you grab a slightly larger group of pixels to confirm that grabScreen() is working?

I was trying to change code i have few versions

something like

pix.grabScreen(mouseX, mouseY, 10, 10);
unsigned char *pixels=pix.getPixels();
ofColor temp;
temp = pix.getPixelsRef().getColor(1, 1);


pix.grabScreen(mouseX, mouseY,10,10);
unsigned char *pixels=image.getPixels();
int index = 0//1,2
int red = pixels[index];
int green = pixels[index+1];
int blue = pixels[index+2];
temp=ofColor(red, green,blue);


pix.grabScreen(mouseX, mouseY, 10, 10);
temp = pix.getColor(1, 1);

I got random value, I mean i click red color, i get for example red, pink, purple, black, white.

I would say that function grabScreen() works bad on raspberry pi. Or it depends on monitor resolution and project resolution?

I think I’ll have to defer to @jvcleave on this one as he has more experience with texture readbacks, etc …

Thanks to @jvcleave , i solved my problem.

It is necessery to run grabScreen() in draw(). Maybe it is not very elegant way, but it works perfect:)