# What am i missing? (createImage)

**URL:** https://discourse.processing.org/t/what-am-i-missing-createimage/470
**Category:** Coding Questions
**Created:** [May 28, 2018, 4:28pm UTC](https://discourse.processing.org/t/what-am-i-missing-createimage/470 "2018-05-28T16:28:47Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Skranker](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@Skranker](https://discourse.processing.org/u/Skranker)
#### Post date: [May 28, 2018, 4:28pm UTC](https://discourse.processing.org/t/what-am-i-missing-createimage/470/1 "2018-05-28T16:28:47Z")

</div>

Hey, i’m simply trying to create an image and set every pixel to white. What am i doing wrong here?

```auto
PImage img;
void setup() {
  img = createImage(500, 500, RGB);
  size(1920, 1080);
}
void draw() {

  img.loadPixels();
  for (int x=0; x<500; x++) {
    for (int y=0; y<500; y++) {
    img.set(x,y,color(255));
    }
  }

image(img,0,0);
}

```

It looks the same here: [https://processing.org/reference/PImage\_set\_.html](https://processing.org/reference/PImage_set_.html)  
Only difference is that i dont want to edit a image file but create a new image instead.

thank you in advance!

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 28, 2018, 4:35pm UTC](https://discourse.processing.org/t/what-am-i-missing-createimage/470/2 "2018-05-28T16:35:36Z")

</div>

Invoke PImage::**get()** w/o any arguments in order to get a clone of it: 😸

- [https://Processing.org/reference/PImage\_get\_.html](https://Processing.org/reference/PImage_get_.html)

---

<div class="post-metadata">

### Author: ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)
#### Post date: [May 28, 2018, 4:40pm UTC](https://discourse.processing.org/t/what-am-i-missing-createimage/470/3 "2018-05-28T16:40:54Z")

</div>

BtW, Arrays::**fill()**:

- [https://Docs.Oracle.com/javase/10/docs/api/java/util/Arrays.html#fill(int[],int)](https://Docs.Oracle.com/javase/10/docs/api/java/util/Arrays.html#fill(int%5B%5D,int))

Over the PImage::_pixels[]_:

- [https://Processing.org/reference/PImage\_pixels.html](https://Processing.org/reference/PImage_pixels.html)

Is much faster than any loop! 💪

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [May 29, 2018, 5:32pm UTC](https://discourse.processing.org/t/what-am-i-missing-createimage/470/4 "2018-05-29T17:32:51Z")

</div>

> [@Skranker](#):
>
> i’m simply trying to create an image and set every pixel to white

I don’t know why you are doing this, but if you want a more general interface to manipulating the pixels of an image, I might recommend PGraphics.

- [PGraphics / Reference / Processing.org](https://processing.org/reference/PGraphics.html)

Now you can call `beginDraw()` and then use Processing methods to do things on your PGraphics `pg`. Want every pixel white? `pg.background(255)`. Want to draw a line? `pg.line(x,y,x2,y2)`. When you are done drawing, remember to call `endDraw()` and then display your image with `image(pg, x, y)`.

```auto
PGraphics pg;

void setup() {
  size(1920, 1080);
  pg = createGraphics(500, 500);
}

void draw() {
  pg.beginDraw();
  pg.background(255);
  pg.endDraw();
  image(pg, 0, 0); 
}

```

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [May 30, 2018, 5:33am UTC](https://discourse.processing.org/t/what-am-i-missing-createimage/470/5 "2018-05-30T05:33:40Z")

</div>

@Skranker When you modifiy your pixels, you need to call `updatePixels()`. Also, as mentioned before, using the pixels array associated with the PImage instead of calling `set()`

`img.pixels[y*img.width+x]=color(255);`

Also in your for loops, instead of using 500, I encourage you to use `image.width` and `img.height` in their respective loops. Good habit to start working on.

Kf
