明白了正與此:
@Test
public void testIcon() throws IOException, InterruptedException {
File file1 = new File("/etc/alternatives/start-here-32.png");
File file2 = new File("/etc/alternatives/start-here-24.png");
BufferedImage img1 = ImageIO.read(file1);
BufferedImage img2 = ImageIO.read(file2);
img1.getGraphics().drawImage(img2, 0, 0, img2.getWidth(null), img2.getHeight(null), 0, 0, img2.getWidth(null), img2.getHeight(null), null);
showImage(img1);
Thread.sleep(10000);
}
這裏是showImage方法:
public void showImage(final BufferedImage image) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setLayout(new BorderLayout());
JPanel imagePanel = new JPanel() {
@Override
public void paint(java.awt.Graphics g) {
g.drawImage(image, 0, 0, image.getWidth(), image.getHeight(), 0, 0, image.getWidth(), image.getHeight(), null);
};
};
frame.getContentPane().add(imagePanel, BorderLayout.CENTER);
frame.setSize(new Dimension(image.getWidth() + 100, image.getHeight() + 100));
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
一些小的變化,使第二個圖像居中在第一個,它的工作完全謝謝 – awestover89 2011-04-26 22:43:23