Hello
I’m trying to load several images into a single PImage object but I’m having issues with transparancy. Rendering the images directly onto the screen goes flawlessly but I’m trying to “buffer” all the layers that make up a single image into a single PImage object.
I’m trying to do this with PImage.pixels[] but it doesn’t seem to work. Here’s what I have;
void draw() {
//background(0);
PImage base = createImage(70, 80, ARGB);
drawOver(base, images.get("right_arm1.png"), 40, 7);
drawOver(base, images.get("right_sleeve_wave1.png"), 40, 26);
image(base, 0, 0);
/*image(images.get("right_arm1.png"), 40, 7);
image(images.get("right_sleeve_wave1.png"), 40, 26);*/
}
void drawOver(PImage base, PImage toAdd, int x, int y) {
int index = (base.width) * y + x;
for (int i = 0; i < toAdd.height; i++) {
for (int j = 0; j < toAdd.width; j++) {
base.pixels[index] = toAdd.pixels[i*toAdd.width + j];
index++;
}
index += base.width-toAdd.width;
}
}
PImage convert(PImage base) {
PImage newImg = createImage(base.width, base.height, ARGB);
for (int i = 0; i < base.pixels.length; i++) {
if (base.pixels[i] == color(255, 255, 255)) {
newImg.pixels[i] = color(255, 255, 255, 0);
} else {
newImg.pixels[i] = base.pixels[i];
}
}
return newImg;
}
convert() is used straight after loading the images to remove whitespace by making them transparant. drawOver() is my way of “buffering” one image into another and the core of it works, just that the result image doesn’t allow for transparancy.