# Why this code not working

**URL:** <https://discourse.processing.org/t/why-this-code-not-working/12886>\
**Category:** Coding Questions\
**Created:** [July 22, 2019, 1:02pm UTC](https://discourse.processing.org/t/why-this-code-not-working/12886 "2019-07-22T13:02:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maakin](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maakin](https://discourse.processing.org/u/maakin)\
**Post date:** [July 22, 2019, 1:02pm UTC](https://discourse.processing.org/t/why-this-code-not-working/12886/1 "2019-07-22T13:02:40Z")

</div>

```auto
PImage img;

void setup() {
  size(200, 200);
  img = loadImage("sunflower.jpg");
}

void draw() {
  loadPixels(); 
  // Since we are going to access the image's pixels too  
  img.loadPixels(); 
  for (int y = 0; y < height; y++) {
    for (int x = 0; x < width; x++) {
      int loc = x + y*width;
      
      // The functions red(), green(), and blue() pull out the 3 color components from a pixel.
      float r = red(img.pixels[loc]);
      float g = green(img.pixels[loc]);
      float b = blue(img.pixels[loc]);
      
      // Image Processing would go here
      // If we were to change the RGB values, we would do it here, 
      // before setting the pixel in the display window.
      
      // Set the display pixel to the image pixel
      pixels[loc] = color(r,g,b);          
    }
  }
  updatePixels();
}

```

---

<div class="post-metadata">

**Author:** ![InferNova](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/infernova/32/6009_2.png) [@InferNova](https://discourse.processing.org/u/InferNova)\
**Post date:** [July 22, 2019, 1:17pm UTC](https://discourse.processing.org/t/why-this-code-not-working/12886/2 "2019-07-22T13:17:13Z")

</div>

Hey There!

Currently not at the pc but can you use loadPixels with the img like that ?

[https://processing.org/reference/loadPixels\_.html](https://processing.org/reference/loadPixels_.html)

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [July 22, 2019, 1:25pm UTC](https://discourse.processing.org/t/why-this-code-not-working/12886/3 "2019-07-22T13:25:28Z")

</div>

what happens and what do you want it to happen instead?

E.g. you don’t change r,g,b so nothing happens of course. Do you mean this?

---

<div class="post-metadata">

**Author:** ![maakin](https://avatars.discourse-cdn.com/v4/letter/m/4af34b/32.png) [@maakin](https://discourse.processing.org/u/maakin)\
**Post date:** [July 22, 2019, 3:18pm UTC](https://discourse.processing.org/t/why-this-code-not-working/12886/4 "2019-07-22T15:18:22Z")

</div>

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/d87e4f1e6fda86d7a013c82de668230fc7caa50a.jpeg)

Why that error coming…,…,

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [July 22, 2019, 3:27pm UTC](https://discourse.processing.org/t/why-this-code-not-working/12886/5 "2019-07-22T15:27:21Z")

</div>

check the image name …

does the file exist in the data folder ?

is it `JPG` or `jpg`?
