# Modify PGraphics pixels array to be larger?

**URL:** <https://discourse.processing.org/t/modify-pgraphics-pixels-array-to-be-larger/40348>\
**Category:** Processing\
**Created:** [December 28, 2022, 11:50pm UTC](https://discourse.processing.org/t/modify-pgraphics-pixels-array-to-be-larger/40348 "2022-12-28T23:50:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![DSW](https://avatars.discourse-cdn.com/v4/letter/d/bbce88/32.png) [@DSW](https://discourse.processing.org/u/DSW)\
**Post date:** [December 28, 2022, 11:50pm UTC](https://discourse.processing.org/t/modify-pgraphics-pixels-array-to-be-larger/40348/1 "2022-12-28T23:50:55Z")

</div>

I’m working on a sketch which composites 60 large images into a single extra-large image.

However, I’m hitting an ArrayIndexOutOfBounds when I initialize the PGraphics object with the required dimensions (65628 x 35292), which I _think_ is being thrown bc the total number of pixels (2,316,143,376) is causing some kind of length problem with the pixels array (or its associated initialization functions)?

I have two questions here: (1) Has anyone made a library which handles images this size? and/or (2) if not, would the thing to do here be to create a new class which extends PGraphics and replaces INTs with FLOATs (or something? It’s been a while since I’ve gone under the hood like this).

Happy to hear any alternatives or ideas y’all may have. Thanks in advance!  
– Devin

---

<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:** [December 29, 2022, 12:33am UTC](https://discourse.processing.org/t/modify-pgraphics-pixels-array-to-be-larger/40348/2 "2022-12-29T00:33:45Z")

</div>

Hello @DSW,

This is the best I could get and took a few minutes to execute:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/5/55b442a697c76f8532834930ec6ee01b207c3013.png)

Memory usage:

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/e/5/e5873797d2577ea1332718b60789bde66d4c8e94.png)

Code:

```auto
// https://en.wikipedia.org/wiki/2,147,483,647
// 2^31-1 = 2,147,483,647
//int signed 32 bits -2147483648 to 2147483647

PGraphics pg;

void setup()
  {
  size(500, 500, P3D);
  pg = createGraphics(65536, 32767);
  println(65536*32767); //2147418112

  println(2147483647); // max size
  
  pg.beginDraw();
  pg.clear();
  pg.endDraw();
  
  pg.loadPixels();
  
  println(pg.pixels.length);
  println("Done!");
  }

```

I could not go over a maximum size of an int:  
[https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html](https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html)

I also had to gin into preferences and increase memory:

![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/5/e/5eb18aee8c2329421c5c9c309c412d98ccdb1fd3.png)

Interesting number:

> **[2,147,483,647](https://en.wikipedia.org/wiki/2,147,483,647)**
>
> The number 2,147,483,647 is the eighth Mersenne prime, equal to 231 − 1. It is one of only four known double Mersenne primes.
> The primality of this number was proven by Leonhard Euler, who reported the proof in a letter to Daniel Bernoulli written in 1772. Euler used trial division, improving on Pietro Cataldi's method, so that at most 372 divisions were needed. It thus improved upon the previous record-holding prime, 6,700,417, also discovered by Euler, forty years earlier. The number 2,147,...

`:)`
