wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Width & Height of the image(URGENT) 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 » Beginning Java
Bookmark "Width & Height of the image(URGENT)" Watch "Width & Height of the image(URGENT)" New topic
Author

Width & Height of the image(URGENT)

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
How to get width and height of the image. Please give me simple example or syntax
Thanks,
Angela
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Angela,
You are kidding right? It probably took you longer to type the question then to look at the API for java.awt.image. Just to make it simple for you allow me to give you a short cut:
ShortCut to java.awt.image API
Regards,
Manfred.
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Thanks Manfred,
I looked API. I did it. IT's not working. It doesn't allow me to compile. Error is "can't fine ImageObserver though i add the class.
That's why I am asking simple example
Thanks
Angela
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Show us what you tried.
Quit using the word URGENT unless you are bleeding.


"JavaRanch, where the deer and the Certified play" - David O'Meara
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

I don't know if this will help ( because I have no idea what you are actually trying to do... ), but I have noticed that sometimes width and height of images return 0 because they are not loaded at the time you are trying to get these attributes. Running the image through a MediaTracker will fix this, though...

-Nate


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Richard Boren
Ranch Hand

Joined: Mar 01, 2001
Posts: 233
Are you doing it like this?
int imageWidth = anImage.getWidth( this ) ;
int imageHeight = anImage.getHeight( this ) ;
Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
Originally posted by Richard Boren:
Are you doing it like this?
int imageWidth = anImage.getWidth( this ) ;
int imageHeight = anImage.getHeight( this ) ;

yes, I am doing like this. First time, I am getting -1 and second time i am getting proper width and height
Thanks
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

Then it looks like my suggestion would solve your problem... before trying to read the width and height values, run the gif through MediaTracker. Normally, an image is not fully loaded into the JVM before it is actually painted to the screen. Loading an image with MediaTracker forces the image to be loaded into the JVM before being displayed.
[This message has been edited by Nathan Pruett (edited July 03, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Width & Height of the image(URGENT)