You can use null for the argument. But you will run into the problem that
getImage is asynchronous. So you have to wait for it to load. The image
class on a whole seems to be hard to deal with. I think there should be a
way to load an image in one line. I also think you should be able to get
height and width info without an argument. It should not take a long time to
figure out how to load an image and get info about it! I hope the sun
programmers are reading this.

    Image im = Toolkit.getDefaultToolkit().getImage( filename );
    try {
      MediaTracker tracker = new MediaTracker(new JPanel());
      tracker.addImage(im, 1);
      tracker.waitForAll(); // load it now, then we can get its width &
height
    } catch (InterruptedException ex) {
      ex.printStackTrace();
    }
    int w = im.getWidth(null);
    int h = im.getHeight(null);

----- Original Message -----
From: Yang Chen <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, October 21, 1999 12:23 PM
Subject: [JAVA2D] getWidth()


> Hello All,
>
> Thank you all for answering my previous problem.
> I have new one, hope you guys can help as well.
> Thank you once again.
>
> -Yang
>
>
>
> img = Toolkit.getDefaultToolkit().getImage(filename);
>         width = img.getWidth(this);
>         height = img.getHeight(this);
>
> *****
> Incompatible type for method. Explicit cast needed to convert FileBrowser
> to java.awt.image.ImageObserver.
>       width = img.getWidth(this);
>                            ^
>       height = img.getHeight(this);
>                              ^
>
>
===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
> of the message "signoff JAVA2D-INTEREST".  For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to