Problem with saving PImage with transparency

Hi, i have written this little program to cut a spritesheet for me, but it doesn’t work with transparency. Anybody know a fix?

PImage sheet = loadImage("dirtTiles.png");
PImage[] tiles = new PImage[25];
int s = 16;

background(200, 100, 100);

String tileName = "dirt";
size(80, 80);

loadPixels();

int index = 0;

for(int x = 0; x < sheet.width; x += s){
  for(int y = 0; y < sheet.height; y += s){
    //tile
    
    PImage cTile = createImage(s, s, RGB);
    
    for(int xt = 0; xt < s; xt++){
      for(int yt = 0; yt < s; yt++){
        
         int sheetindex = x + xt + (y + yt) * sheet.width;
         int tileindex = xt + yt * s;
         
         
         
           cTile.pixels[tileindex] = sheet.pixels[sheetindex];
         
        
      }
    }
    
    cTile.updatePixels();
    tiles[index] = cTile;
    index++;
    
    
  }
}



for (int i = 0; i < tiles.length; i++) {
    tiles[i].save(tileName + str(i));
    
}

besides that the array length missmatch,
the used filename causes to save a *.tif file,
https://processing.org/reference/save_.html
you could try as *.png ??

    tiles[i].save("data/"+tileName +"_"+ str(i)+ ".png");

Thanks, but the transparency is still not perserved. It is replaced with black pixels.

EDIT: Idk if i was clear enough. The program works fine, the problem is that the the transparent pixels is the image “sheet” isn’t perserved in the output tiles.

ARGB instead RGB ???

https://processing.org/reference/createImage_.html

That did it, thank you!