How to split image into several ones (spirtes)

Hi!
I am trying to make the basics for chess and I am interested how to turn an image into an array of sprites.

Code
PImage source = loadImage("chessPieces2.png");
println(source.width, source.height);
size(1200, 400);
background(0);
rect(0, height/2, width, height/2);
noFill();
stroke(255);
image(source, 0, 0);
float m = 1.333, scl = 130*m, xoff = 10*m, yoff = 10*m, xbuffer=20*m, ybuffer=20*m;
for (int j = 0; j < 2; j++) {
  for (int i = 0; i < 6; i++) {
    rect(xoff+i*scl+(i*xbuffer), yoff+j*scl+(j*ybuffer), scl, scl);
  }
  stroke(0);
}

I want to split this image (transparent png in the background) into 12 sprites. I know the exact position of every square and the image is names “chessPieces2.png” (here:)

How do I do it?

img.get(x,y,w,h)

is the solution : P

2 Likes