Réponse acceptée !
Salut,
la solution la plus spontanée que j'ai et pas forcément la plus belle, ni la plus optimisée, mais là comme ça et au vu de ma flème de me creuser la tete :
Note : Ici seul la méthode append t'intéresse, le reste c'est juste pour l'exemple d'utilisation
import java.awt.Graphics2D; import java.awt.Image; import java.awt.image.BufferedImage;
import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel;
public class Test {
public static Image append(Image img1, Image img2) { BufferedImage buf = null; if(img1 != null && img2 != null) { int w1 = img1.getWidth(null); int h1 = img1.getHeight(null); int w2 = img2.getWidth(null); int h2 = img2.getHeight(null); int hMax = 0; int wMax = 0; hMax = (h1 >= h2) ? h1 : h2; wMax = w1+w2; buf = new BufferedImage(wMax, hMax, BufferedImage.TYPE_INT_ARGB); Graphics2D g2 = buf.createGraphics(); g2.drawImage(img1, 0, 0, null); g2.drawImage(img2, w1, 0, null); } return buf; } public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(3); f.setSize(800, 600); f.setLocationRelativeTo(null); ImageIcon img1 = new ImageIcon("img1.png"); ImageIcon img2 = new ImageIcon("img2.png"); ImageIcon image = new ImageIcon(append(img1.getImage(), img2.getImage())); JLabel label = new JLabel(); label.setIcon(image); f.setContentPane(label); f.setVisible(true); } }
------------------------------------ "On n'est pas au resto : ici on ne fait pas dans les plats tout cuits ..."
OoWORAoO
|