getPixels to ofSetColor

I’m trying to get ofSetColor to use a colour from getPixels so that I can draw using the colour from an image below the cursor.

in .h

  
  
char		r;  
char		g;  
char		b;  
unsigned char * pixels;  
ofImage screen;  
  

in setup

  
  
screen.grabScreen(0, 0, ofGetHeight(), ofGetWidth());  
pixels = screen.getPixels();  
printf("bpp = %i",screen.bpp); // returns 24  
  

in draw

  
  
r = pixels[(mouseY * ofGetWidth() + mouseX)*3+0];  
g = pixels[(mouseY * ofGetWidth() + mouseX)*3+1];  
b = pixels[(mouseY * ofGetWidth() + mouseX)*3+2];  
ofSetColor(int(r),int(g),int(b));  
  

Now it’s doing something but its way off as you can see. Looks like its more a problem with the data I’m getting out of the pixels object because the grey at the top isn’t uniformly the wrong colour.

If I printf r,g,b

  
printf("r=%c b=%c g=%c\n",r,g,b);  

I get stuff like this

  
r= b=\252 g=8  
r=\366 b=\245 g=\366\366r= b=\252 g=  
r=\366 b=\245 g=  
r=\325 b=\241 g=\366\366r=\313 b=\200 g=\252  
r=\353 b=\200 g=\312\312r=O b=\201 g=/  
r=P b=\201 g=p  
r=/ b=\201 g=O  
r=O b=\201 g=p  
r=P b=\201 g=Q  
r=\353 b=\200 g=\313\313r=\354 b=\200 g=\313\313r=h b=\200 g=\251  
r=\221 b=\201 g=\221  
  

Thanks! My first OF project

ok found my code worked fine with an ofImage I loaded in but not with grabscreen.
http://forum.openframeworks.cc/t/grabscreen-for-iphone/3037/0
someone else with a similar problem. So is there any way of getting that texture data into an ofimage?

Solved it by not capturing the screen at all and just working out the offsets of the drawn image and the paint.