Skip to content

Instantly share code, notes, and snippets.

@aNNiMON
Created September 26, 2014 07:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aNNiMON/0869aa042fc26d9f97cf to your computer and use it in GitHub Desktop.
Save aNNiMON/0869aa042fc26d9f97cf to your computer and use it in GitHub Desktop.
Join Images by ARGB-array
private BufferedImage joinHorizontally(BufferedImage[] img) {
// Считаем ширину всех картинок
int width = img[0].getWidth() * img.length;
//int width = 0;
//for (int i = 0; i < img.length; i++) width += img[i].getWidth();
// Создаём массив ARGB для полной картинки
final int[] all = new int[width*img[0].getHeight()];
for (int i = 0; i < img.length; i++) {
// Получаем пиксели очередной картинки
final int w = img[i].getWidth(), h = img[i].getHeight();
final int[] rgb = new int[w * h];
img[i].getRGB(0, 0, w, h, rgb, 0, w);
// Копируем построчно
for (int y = 0; y < h; y++) {
System.arraycopy(rgb, y * w, all, i * w + y * ((img.length - 1) * w) + y * w, w);
}
}
BufferedImage image = new BufferedImage(width, img[0].getHeight(), BufferedImage.TYPE_INT_ARGB);
image.setRGB(0, 0, width, img[0].getHeight(), all, 0, width);
return image;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment