Forums Register Login

Width & Height of the image(URGENT)

+Pie Number of slices to send: Send
How to get width and height of the image. Please give me simple example or syntax
Thanks,
Angela
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Show us what you tried.
Quit using the word URGENT unless you are bleeding.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
Are you doing it like this?
int imageWidth = anImage.getWidth( this ) ;
int imageHeight = anImage.getHeight( this ) ;
+Pie Number of slices to send: Send
 

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
+Pie Number of slices to send: Send
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).]
It was the best of times. It was the worst of times. It was a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 751 times.
Similar Threads
width and height using image object
Is there a way to show an image in a JTable as a thumbnail?
How to get Height and width without loading image in memory
draw Image
draw Image
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 07:57:19.