如何在JPanel中加载图像?

时间:2013-01-03 00:53:57

标签: java image swing png jpanel

我有一个PNG图像,我想用它作为画笔。

我想给JPanel画一些东西。

如何加载图像以用作JPanel的画笔?

1 个答案:

答案 0 :(得分:0)

final Image image = new ImageIcon("C:/images/image.png").getImage();
JPanel panel = new JPanel() {
    @Override
    protected void paintComponent(Graphics g) {
        g.drawImage(imageToPaint, 
            (desired x location), (desired y location), null);
    }
};