I'm creating a function using JavaFX so that it uses two images and the size of the pixels and returns a third image containing a chess effect from the other two images.
Below is the code,
public Image xadrez(Image img1, Image img2, int tamanho) {
int larg = (int) img1.getWidth();
int alt = (int) img1.getHeight();
WritableImage imgRes = new WritableImage(larg, alt);
PixelReader pr = img1.getPixelReader();
PixelReader pr2 = img2.getPixelReader();
PixelWriter pw = imgRes.getPixelWriter();
for (int x = 0; x < larg; x++) {
for (int y = 0; y < alt; y++) {
if ( x % 2 == y % 2)
pw.setArgb(x, y, pr.getArgb(x, y));
else
pw.setArgb(x, y, pr2.getArgb(x, y));
}
}
return imgRes;
}
The whole problem is that I'm not able to arrange a way to put the size of the pixels, the above code returns an image with the effect chess but using only 1 pixel of each image at a time. What I would like to do is use the variable size to get a larger group of pixels, such as 10 pixels at a time.