Created
September 26, 2014 07:36
-
-
Save aNNiMON/0869aa042fc26d9f97cf to your computer and use it in GitHub Desktop.
Join Images by ARGB-array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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