Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Width & Height of the image(URGENT)

 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to get width and height of the image. Please give me simple example or syntax
Thanks,
Angela
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Show us what you tried.
Quit using the word URGENT unless you are bleeding.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Richard Boren
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you doing it like this?
int imageWidth = anImage.getWidth( this ) ;
int imageHeight = anImage.getHeight( this ) ;
 
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic