Skip to main content
GameDev.net gamedev.net
🔒 Locked

[java] Load image - ImageIcon() vs Toolkit.getImage() ?

Started by CodeMachine Oct 10, 2006 at 10:52 AM 3 replies 4.1k views
Original Post
CodeMachine
CodeMachine
Hi Right now I use

 MediaTracker mt = new MediaTracker(com);
 Image img = Toolkit.getDefaultToolkit().getImage("image.png");
 try {
  mt.addImage(img,0); 
  mt.waitForAll();
 } catch(Exception e) {}

Is it better or worse to use

 Image = new ImageIcon("image.png").getImage();

? Correct me if Im wrong, but doesn't ImageIcon automatically implements a kind of "MediaTracker"? / Kind Regards
Angex
Angex
You're right, ImageIcon just implements a MediaTracker.

I tend to use ImageIcon 's when working with just Swing as a time-saver. For more complex applications with images I use the ImageIO because (imo) it makes using multiple formats and BufferedImage 's easier.
CodeMachine
CodeMachine
So if I use ImageIcon or getImage+Mediatracker, it doesn't matter?
Angex
Angex
It doesn't really matter, just use the method you prefer

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.