2

I have a list of images. I want to merge them into one image so that they line up vertically in the new image. Research pointed me to this code but struggling to align them

BufferedImage result = new BufferedImage(
                    width, height, //work these out
                    BufferedImage.TYPE_INT_RGB);
                    Graphics g = result.getGraphics();

                    for(String image : imgFiles){
                        BufferedImage bi = ImageIO.read(new File(image));
                        g.drawImage(bi, x, y, null);
                        x += 256;
                        if(x > result.getWidth()){
                            x = 0;
                            y += bi.getHeight();
                        }
                    }
Lez
  • 161
  • 1
  • 1
  • 13
  • Possible duplicate of [Layer multiple BufferedImages on top of one another?](https://stackoverflow.com/questions/11148453/layer-multiple-bufferedimages-on-top-of-one-another) – Ascalonian May 23 '18 at 15:30
  • What happens when you run the above code? And in what way does that differ from your expected or desired result? Adding some images for actual vs desired result also sounds like a good idea for this question. Also, are you merging arbitrary sized images or are they all of equal size? – Harald K May 24 '18 at 06:54

0 Answers0