In Swing (components with J prefix) it is better not to use a Canvas which is an AWT, heavyweight component. Use a JPanel instead. See [url=http://java.sun.com/products/jfc/tsc/articles/mixing/]Mixing Heavy and Light Components[/url] for details.
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.*;
import javax.imageio.ImageIO;
import javax.swing.*;
public class SimpleImage {
public static void main(String[] args) throws IOException {
// The images folder is in the current directory.
String path = "images/Bird.gif"; // jpg, png and bmp okay
BufferedImage image = ImageIO.read(new File(path));
JLabel label = new JLabel(new ImageIcon(image));
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().setLayout(new GridLayout(1,0));
f.getContentPane().add(label);
f.getContentPane().add(new BirdPanel(image));
f.pack();
f.setVisible(true);
}
}
class BirdPanel extends JPanel {
BufferedImage image;
public BirdPanel(BufferedImage image) {
this.image = image;
}
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(image, 0, 0, this);
}
}