Skip to content

Instantly share code, notes, and snippets.

@Mr00Anderson
Created October 14, 2020 18:22
Show Gist options
  • Save Mr00Anderson/bea98dab3c768df03a3b9d35da7d9f25 to your computer and use it in GitHub Desktop.
Save Mr00Anderson/bea98dab3c768df03a3b9d35da7d9f25 to your computer and use it in GitHub Desktop.
//Overlays using pixel from base images and making a percent darker
public static Pixmap combineImages(final Pixmap basePixmap, final Pixmap overlayPixmap) {
final Pixmap newPixmap = new Pixmap(basePixmap.getWidth(), basePixmap.getHeight(), basePixmap.getFormat());
final int adjustedWidthIndex = basePixmap.getWidth();
final int adjustedHeightIndex = basePixmap.getHeight();
for (int row = 0; row < adjustedHeightIndex; row++) {
for (int column = 0; column < adjustedWidthIndex; column++) {
final int basePixel = basePixmap.getPixel(column, row);
final int overlayPixel = overlayPixmap.getPixel(column, row);
if (isTranslucent(overlayPixel)) {
newPixmap.drawPixel(column, row, 0); /* Set translucent if is translucent color*/
} else if (overlayPixel == 0) {
newPixmap.drawPixel(column, row, basePixel);
} else {
newPixmap.drawPixel(column, row, overlayPixel);
}
}
}
return newPixmap;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment