yeah, this would do.
Nik
Main Topics
Browse All TopicsHi there.
Here's my problem: I need to load many images into my gui. I would like to load one gif file that contains an imageMap of all the icons needed, and load one text file that tells me the xy coordinates of all these icons. I then would like to create a seperate image for each icon, and place them in a repository (hashtable). I figured I would save time by only loading one gif file as opposed to 50 to 100 gif files. The less the program needs to access the harddrive the better right?
I can load the file fine, and get the text description ok, but I'm stuck on how to create the seperate images from the one imageMap. Normally, if my class extended Component, then I could just call createImage, but I'm under the impression that this will only work if that component is visible. Besides I'm trying to have a small class here, and I don't need the overhead of Component.
Does anyone have a clue how I would do this??
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
It looks like it should work but I must be doing something wrong. I load the imagemap in correctly and I verify that it is the correct size (in this case 640X480). And then I attempt to create the smaller images out of the larger one using your method, but all the images return that the Width and Height are -1.
Heres what I used:
iTemp = Toolkit.getDefaultToolkit(
System.out.println("Temp : W = " + iTemp.getWidth(this) + " H=" + iTemp.getHeight(this));
where x,y,w, and h are all known and correct values.
Why does it always return -1?
Thanks
The problem stems from the fact that the getImage returns immediatelly and you cannot be sure the bits that comprise the image have arrived. That is why MediaTracker is needed. If this 'loading' makes you application GUI freeze, use another thread, and change the GUI as appropriate when the image arrives.
Cheers,
Nik
Business Accounts
Answer for Membership
by: OviPosted on 2000-02-17 at 22:27:40ID: 2533845
You have here a method of mine which can read an gif image wich contains 45 icons arranged in line. You see in the code "treeBuilder" object. This is the instantiation of a class which extends java.applet.Applet;
uilder.get CodeBase() , "iconmap.gif"); mage, treeBuilder); e, 0); reateImage (new FilteredImageSource(image. getSource( ), new CropImageFilter(j * 16, 0, 16, 16)));
Also I supose that each image (icon) is a square with 16 width&heigth ( non english speaker).
public void buildImgVector()
{
if(iconArray == null)
iconArray = new Image[45];
Object obj;
try
{
Image image = treeBuilder.getImage(treeB
treeBuilder.prepareImage(i
MediaTracker mediatracker = new MediaTracker(treeBuilder);
mediatracker.addImage(imag
mediatracker.waitForID(0);
int j = 0;
do
iconArray[j] = treeBuilder.getToolkit().c
while(++j < 45);
return;
}
catch(Exception _ex)
{
obj = null;
}
}