aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Loading an Array of Images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Loading an Array of Images" Watch "Loading an Array of Images" New topic
Author

Loading an Array of Images

mark geroso
Greenhorn

Joined: Oct 12, 2006
Posts: 24
Hi.
Is this the right way to load an array of images?
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
Is this the right way to load an array of images?
So far, so good: you're on the right track. This instantiates the image array but does not actually load the image data. The Toolkit getImage and creatImage methods return immediately, ie, they load synchronously. What you want for image loading is to block program execution until all the images are fully–loaded. To do this we use the MediatTracker class. See the class api for example code and handy methods for checking on the loading status.
Also, while we're at it, check out the information for (the Toolkit method) getImage in the (Toolkit) Method Detail section: it explains why getImage may not be the best choice.
This is the older way to load images. We have two other, later options:
ImageIcon was introduced in j2se1.2 and uses the Toolkit and MediaTracker classes for loading images. One drawback of this appraoch is that it gives no indication/exception if the file is not found or the data is corrupted/not loaded. It's api does provide ways to find out about loading trouble/success.
In j2se 1.4 ImageIO was introduced and is the newest way to load images. It throws exceptions for loading trouble.
mark geroso
Greenhorn

Joined: Oct 12, 2006
Posts: 24
Thank you Craig.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading an Array of Images