# Cannot understand PImage

**URL:** <https://discourse.processing.org/t/cannot-understand-pimage/38070>\
**Category:** Coding Questions\
**Created:** [July 24, 2022, 11:22am UTC](https://discourse.processing.org/t/cannot-understand-pimage/38070 "2022-07-24T11:22:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MSousa](https://avatars.discourse-cdn.com/v4/letter/m/c0e974/32.png) [@MSousa](https://discourse.processing.org/u/MSousa)\
**Post date:** [July 24, 2022, 11:22am UTC](https://discourse.processing.org/t/cannot-understand-pimage/38070/1 "2022-07-24T11:22:53Z")

</div>

//Pimage test  
/\* Trying to undersand Pimage  
created a Pimage object named img  
the idea is to acquire data from the Teensy  
microcontroller and fill the img area.

line 27 fills the image with a stored jpg image  
line 30 places the image in the 400x400 window at a specified location

if the location position is image(img,0,0)  
the below example works fine. If you move the position  
to image(img,75,75) the program does not work correctly.

Why?

\*/

PImage img;  
int i;  
int x = 0;  
int y = 0;  
int loc;

void setup() {  
size(400,400);  
img = loadImage(“Test256.jpg”);  
background(90);  
//image(img,0,0);  
image(img,50,50);  
img.loadPixels();  
textSize(24);  
}

void draw() {  
mousePos();  
fillColor();  
}

void mousePos() {  
fill(50);  
rect(185,360,50,25);  
fill(255);  
text(“mouseX”,100,380);  
text(mouseX,190,380);  
fill(50);  
rect(340,360,50,25);  
fill(255);  
text(“mouseY”,250,380);  
text(mouseY,340,380);  
}

void fillColor() {  
color c = img.get(mouseX,mouseY);  
fill(c);  
rect(0,350,50,50);  
}

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [July 24, 2022, 1:40pm UTC](https://discourse.processing.org/t/cannot-understand-pimage/38070/2 "2022-07-24T13:40:27Z")

</div>

Hello @MSousa,

Please format your code as per instructions here:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

Consider:

```auto
color c = img.get(mouseX, mouseY); // Gets the color or the pixel in the PImage img
//color c = get(mouseX, mouseY); // Gets the color of pixel in the sketch window

```

References for get (there are two of them):

[https://processing.org/reference/get\_.html](https://processing.org/reference/get_.html)  
[https://processing.org/reference/PImage\_get\_.html](https://processing.org/reference/PImage_get_.html)

You could also add an offset here:

`color c = img.get(mouseX - offX, mouseY - offY); // Gets the color or the pixel in the PImage img`

Think about that last one and how much you want to offset.

`:)`
