stalefish
asked on
Loading multiple images from One Image Map
Hi 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
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
yeah, this would do.
Nik
Nik
ASKER
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( ).createIm age(new FilteredImageSource(map.ge tSource(), new CropImageFilter(x, y, w, h)));
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
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
ASKER
Ok I just figured out that if I put a mediaTracker after each iteration of iTemp, then I get the correct image back.
Is there any way of avoiding the media tracker? Why do I have to use it in my code, and you don't in yours?
I'm trying to make this method as fast as possible.
Thanks
Is there any way of avoiding the media tracker? Why do I have to use it in my code, and you don't in yours?
I'm trying to make this method as fast as possible.
Thanks
ASKER
Ok I just figured out that if I put a mediaTracker after each iteration of iTemp, then I get the correct image back.
Is there any way of avoiding the media tracker? Why do I have to use it in my code, and you don't in yours?
I'm trying to make this method as fast as possible.
Thanks
Is there any way of avoiding the media tracker? Why do I have to use it in my code, and you don't in yours?
I'm trying to make this method as fast as possible.
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
Cheers,
Nik
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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;
}
}