我想在我的面板中绘制一个gif图像,问题是我的代码绘制jpg图像很好,但我没有绘制gif图像。这就是我的代码的样子。
public class DrawingPanel extends JPanel {
Image image;
public DrawingPanel() {
setPreferredSize(new Dimension(600,600));
setBackground(Color.CYAN);
image = new ImageIcon("C:\\Users\\Hp\\Downloads\\loading.gif").getImage();
}
@Override
protected void paintComponent(Graphics g) {
// TODO Auto-generated method stub
super.paintComponent(g);
g.drawImage(image, 0, 0, getWidth(), getHeight(), null);
}
答案 0 :(得分:0)
BufferedImage image;
image = ImageIO.read(new File("image name and path"));
使用ImageIO
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, null);
}