# Pixel get() buggy in Processing 4.1?

**URL:** <https://discourse.processing.org/t/pixel-get-buggy-in-processing-4-1/41422>\
**Category:** Processing\
**Created:** [March 23, 2023, 11:27pm UTC](https://discourse.processing.org/t/pixel-get-buggy-in-processing-4-1/41422 "2023-03-23T23:27:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jaz](https://avatars.discourse-cdn.com/v4/letter/j/4491bb/32.png) [@Jaz](https://discourse.processing.org/u/Jaz)\
**Post date:** [March 23, 2023, 11:27pm UTC](https://discourse.processing.org/t/pixel-get-buggy-in-processing-4-1/41422/1 "2023-03-23T23:27:22Z")

</div>

I am attempting to get the color of each pixel in an image. Using the get() function with coordinates yield garbage values or strange results (only a single color from the image rather than the color at a particular x,y point).  
The image shows up fine. If I use the pixels array I can get the colors correctlu, but not the get() function.

```auto
PImage img;
size(400, 300); //4:3
img = loadImage("myjpg.jpg");
image(img, 0,0, width, height);

// draw a square every 5 pixels with the fill color the same as a pixel at that point
for(int i=0; i < width*height; i+=5){
  int x = i%width;
  int y = floor(i/width)*5;
  color c = get(x, y); // <--- have tried both img.get(x,y) and get(x,y) based on reference. 
  fill(red(c), green(c), blue(c), 255); //same results as fill(c)
  rect(x, y, 20, 20);
}

```

Is this a bug or am I doing something incorrectly?

---

<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:** [March 24, 2023, 12:38am UTC](https://discourse.processing.org/t/pixel-get-buggy-in-processing-4-1/41422/2 "2023-03-24T00:38:15Z")

</div>

Hello @Jaz,

This works with Processing 4.2:

```auto
PImage img;
size(800, 400);
String url = "http://learningprocessing.com/code/assets/sunflower.jpg";
img = loadImage(url);
img.resize(400, 400);
image(img, 0, 0);

// draw a square every 5 pixels with the fill color the same as a pixel at that point
for(int i=0; i < width*height; i+=10)
  {
  int x = i%img.width;
  int y = floor(i/img.height)*10;
  color c = img.get(x, y); // get() or img.get () works!
  //fill(red(c), green(c), blue(c), 255); //same results as fill(c)
  fill(c);
  rect(x+width/2, y, 10, 10);
  }

```

I suspect that you were overwriting the pixels with a _rect()_ and then using _get()_.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/6/c/6c70f9f3080720f01b1649dee83ff3e3ee8af2c2.jpeg)

`:)`
