How can I know if Image is nothing?

G

Guest

I use this code:
--------
URL urlAdv = new URL(getCodeBase() + "/adv.php?" + timeblock);
Image tmp = getImage(urlAdv);
--------
This page "adv.php" some times return "Error 404, Page not found".
I want to know when Image tmp is valid and when not.
How?

Thanks
 
T

Tim Tyler

:> > I tried with:
:> > --------
:> > if (tmp.getHeight != -1) ImageIsValid();
:> > --------
:> > but this member always returns -1?
:> > With which method can I get the Image height?
:>
:> Try follow:
:> if( tmp.getImageLoadStatus() != java.awt.MediaTracker.COMPLETE )
:> ImageNotValid()
:> else ImageIsValid()

: getImageLoadStatus is not an Image member

getImageLoadStatus() is a method in ImageIcon.

However, the idea was sound - the reason you are not getting the image
height correctly is probably because it has not finished loading yet.

Using getToolkit().prepareImage(image.getImage(), -1, -1, null)
....is one way to tell if an image has been loaded yet.

You can use that in a loop, to wait for it to happen:

do {
try {
Thread.sleep(50);
}
catch (InterruptedException e) {
}
} while (!imageLoaded());
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,434
Messages
2,571,685
Members
48,796
Latest member
Greg L.

Latest Threads

Top