# Grid of Images PImage error

**URL:** <https://discourse.processing.org/t/grid-of-images-pimage-error/46496>\
**Category:** Beginners\
**Created:** [June 2, 2025, 8:22pm UTC](https://discourse.processing.org/t/grid-of-images-pimage-error/46496 "2025-06-02T20:22:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikapm](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/nikapm/32/20715_2.png) [@nikapm](https://discourse.processing.org/u/nikapm)\
**Post date:** [June 2, 2025, 8:22pm UTC](https://discourse.processing.org/t/grid-of-images-pimage-error/46496/1 "2025-06-02T20:22:57Z")

</div>

Hello, I am kind of new to processing and I am building an image grid using 2d array, but I don’t know why I keep getting this error message :"Types mismatch: cannot convert from `PImage` to `Pimage []`. I made my research and I couldn’t find a better way to declare the array, can anyone gime a light?  
Here’s the code:

```processing
PImage[][] images = new PImage[5][5];

void setup() {
  size(1000, 1000);   
  
  frameRate(30);
}

void draw() {

int column = 5;
int rows = 5;
 

  for (int i = 0; i <5; i++){
  PImage img = loadImage(""+i+".png");
  images[i] = img;
}

for(int j = 0; j < 5; j++){
  PImage img1 = loadImage(""+j+".png");
  images[4+j] = img1;
}
for (int i = 0; i < column; i++) {
  for (int j = 0; j < rows; j++) {
   images[i][j] = loadImage(""+i+".png");
  image(img, 0, 0, rows, column);
  image(img1, rows, column, rows, column);
}
}

}

```

---

<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:** [June 2, 2025, 8:34pm UTC](https://discourse.processing.org/t/grid-of-images-pimage-error/46496/2 "2025-06-02T20:34:02Z")

</div>

> [@nikapm](#):
>
> "Types mismatch: cannot convert from PImage to Pimage[]

Function **loadImage()** returns a PImage object.

However, at the statement `images[i] = img;`, the `images[i]` represents an array of PImage objects; b/c variable _images_ is a 2D-array.

`images[4+j] = img1;` is also wrong! Take a look at the concept of 2D-arrays:

> **[Two-Dimensional Arrays](https://processing.org/tutorials/2darray/)**
>
> Store and acess data in a matrix using a two-dimensional array.

---

<div class="post-metadata">

**Author:** ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)\
**Post date:** [June 2, 2025, 9:02pm UTC](https://discourse.processing.org/t/grid-of-images-pimage-error/46496/3 "2025-06-02T21:02:54Z")

</div>

The function `setup()` gets called one time, but `draw()` gets called repeatedly. You presumably only want to load your images once, so move all your code that loads the images into `setup()`, leaving the `image()` calls in `draw()`. If, however, you only plan to display the images once and not move or interact with them, you could move the drawing code into `setup()` as well or add `noLoop()` to `setup()` which will cause `draw()` to be called only once.

But first address what @GoToLoop mentioned. `image[][]` is an array of arrays. Before you can fill it with images, you have to create each of its 1-D row arrays.

OR

You could replace the 2-D array with a simpler 1-D array of 25 images and do the little bit of math needed to index them into a square yourself. For instance, the image at `i`,`j` would be `images[i+j*5]`.

---

<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:** [June 8, 2025, 12:44am UTC](https://discourse.processing.org/t/grid-of-images-pimage-error/46496/4 "2025-06-08T00:44:47Z")

</div>

> [@scudly](#):
>
> You could replace the 2-D array with a simpler 1-D array of 25 images and do the little bit of math needed to index them into a square yourself. For instance, the image at `i`,`j` would be `images[i+j*5]`.

This tutorial also discusses this method in the _ **Pixels, pixels, and more pixels** _ section:

> **[Images and Pixels](https://processing.org/tutorials/pixels/#pixels-pixels-and-more-pixels)**
>
> How to load and display images as well as access their pixels.

 ![image](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/c/7/c7befea16e9830dc572eac58516ed625c7fa70a0.png)

`:)`
