Join 2 images in Java [closed]

-1

Good, I am trying to join 2 images in java, one of them is a number that is in one image and the other is a black background with a small white hole to put the number, I would like to know if it is possible to place that number number in the hole and then save the image, thanks! Example:

I have this barcode:

And, I have to put it in this image:

    
asked by fer112233 01.11.2016 в 17:42
source

1 answer

2

We can use BufferedImage to make the combination

BufferedImage biUno= ImageIO.read(new File("uno.png"));
BufferedImage biDos = ImageIO.read(new File("dos.png"));


BufferedImage biResultado = new BufferedImage(1024, 256, BufferedImage.TYPE_INT_ARGB); //suponiendo tamaño de imagen  y ARGB que soporta trasparencia

Graphics g = biResultado.getGraphics();
g.drawImage(biUno, 0, 0, null); //se rellena con imagen uno
g.drawImage(biDos, 5, 5, null); //se rellena con imagen dos con  un supuesto margen de 5 (habria que ver cual es el real)


ImageIO.write(biResultado, "PNG", new File("resultado.png"));
    
answered by 01.11.2016 в 18:15