# Overwriting pixels\[\] Manually

**URL:** <https://discourse.processing.org/t/overwriting-pixels-manually/29306>\
**Category:** Coding Questions\
**Created:** [April 12, 2021, 4:57pm UTC](https://discourse.processing.org/t/overwriting-pixels-manually/29306 "2021-04-12T16:57:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![what42](https://avatars.discourse-cdn.com/v4/letter/w/8491ac/32.png) [@what42](https://discourse.processing.org/u/what42)\
**Post date:** [April 12, 2021, 4:57pm UTC](https://discourse.processing.org/t/overwriting-pixels-manually/29306/1 "2021-04-12T16:57:16Z")

</div>

I just wanted to know if there’s any way I can bypass loadPixels() and just do `pixels = new int [width * height];`. I have a function that renders a tilemap to an int array, and load&updatePixels() is slowing it down quite a lot, so anything I can do to mitigate this would be really helpful!

I’ve tried

```auto
//loadPixels();
pixels = new color [width * height];
Render (pixels);
updatePixels();

```

and it doesn’t seem to render anything to the screen. I thought it would either work or crash, but it doesn’t do either. It just doesn’t do anything at all, which is pretty weird. I’ve also tried commenting out (only) updatePixels(), but that has the exact same effect (which is no effect at all). If anyone knows a better way to work with this, please let me know!

(also, I know I probably just shouldn’t use processing for this, but I want to know if there’s any way to make this (the overwriting pixels[]) work)

---

<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:** [April 12, 2021, 6:30pm UTC](https://discourse.processing.org/t/overwriting-pixels-manually/29306/2 "2021-04-12T18:30:33Z")

</div>

Hello,

There is a tutorial here:  
_[Images and Pixels / Processing.org](https://processing.org/tutorials/pixels/)_

Coding Train:  
_[https://www.youtube.com/watch?v=EmtU0eloTlE](https://www.youtube.com/watch?v=EmtU0eloTlE)_  
_[https://www.youtube.com/watch?v=j-ZLDEnhT3Q](https://www.youtube.com/watch?v=j-ZLDEnhT3Q)_

`:)`

---

<div class="post-metadata">

**Author:** ![micycle](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/micycle/32/201_2.png) [@micycle](https://discourse.processing.org/u/micycle)\
**Post date:** [April 12, 2021, 10:25pm UTC](https://discourse.processing.org/t/overwriting-pixels-manually/29306/3 "2021-04-12T22:25:24Z")

</div>

You can bypass `loadPixels()` like this:

```auto
void setup() {
  size(800, 800);
  g.pixels = new color [width * height];
}

void draw() {
  for (int i = 0; i<g.pixels.length; i++) {
    g.pixels[i] = color(255, 0, 255);
  }
  updatePixels();
}

```

You can’t get around needing `updatePixels()` **unless** you write directly to the underlying render-dependent buffer, in which case you’ll need to dig around the internals a little. This is possible – I’ve done it with JavaFX at least – but don’t have the code right now (with lockdown I’m away from my main PC).

---

<div class="post-metadata">

**Author:** ![what42](https://avatars.discourse-cdn.com/v4/letter/w/8491ac/32.png) [@what42](https://discourse.processing.org/u/what42)\
**Post date:** [April 18, 2021, 10:32pm UTC](https://discourse.processing.org/t/overwriting-pixels-manually/29306/4 "2021-04-18T22:32:06Z")

</div>

thanks so much! It’s really nice to have people like you!
