Results 1 to 11 of 11
Thread: Get Image Height and Width
- 02-16-2009, 01:16 PM #1
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
Get Image Height and Width
Hi all,
i am trying to get the height and width of an imgae,
see below
url = new URL("some url of an image");
Image img = Toolkit.getDefaultToolkit().getDefaultToolkit().cr eateImage(url);
img.getHeight(....?????);
but not able to get the real height and width.
i am trying to put null at ????..
Thank you.
Regards,
Neeraj
- 02-16-2009, 03:28 PM #2
Try
BufferedImage image = ImageIO.read(url);
Image is an abstract class; BufferedImage seems to be the most common concrete subclass. Look at the BufferedImage API.
- 02-17-2009, 05:55 AM #3
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
In general, images are read asynchronously. To guarantee the image has been completely read, you would need to call 'getHeight' with a non-null ImageObserver that you've implemented to guarantee the read is complete. I did this one time when I was trying to eke every microgram of performance out of an application (it's slightly faster to do it this way than to use ImageIO), but it's much more complicated than just doing what Steve recommended, which handles all that mess for you.
- 02-17-2009, 07:03 AM #4
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
hi steve,
Thanks for the help, but dear..
i dont find any method like read() in bufferedimage / image class.
i am also confused how to use ImageObserver, please help me with this.
Thanks
regards,
- neeraj
- 02-17-2009, 09:29 AM #5
- 02-17-2009, 10:34 AM #6
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
wt is imageIO? how to use it?
- 02-17-2009, 10:57 AM #7
- 02-17-2009, 03:03 PM #8
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
ImageIO is a class in the javax.imageio package, which is part of the core Java distribution. With questions this basic, I strongly discourage you from moving forward with the Toolkit approach.
Last edited by toadaly; 02-17-2009 at 03:06 PM.
- 02-17-2009, 03:07 PM #9
Member
- Join Date
- Feb 2009
- Location
- Delhi
- Posts
- 63
- Rep Power
- 0
hello toadaly,
then you tell me how can i get the image's height...
its not a simple image... i am getting the image from some url..
thanks in advance
/\/
- 02-18-2009, 06:08 AM #10
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
Follow the advice Steve gave. Is there a reason you're ignoring him? ImageIO works with URLs, files, jar files, etc.
- 02-18-2009, 01:09 PM #11
To ImageIO or not to ImageIO
For those who doubted that ImageIO existed...
ImageIO (Java Platform SE 6)
... and guess what?... it does have a read() method... as a matter of fact , it has 4 read() methods.
Luck,
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
Similar Threads
-
How do you determine the width of a TableColumn heading?
By The Gonif in forum SWT / JFaceReplies: 2Last Post: 03-01-2011, 01:30 AM -
Java Syntax for making 2 divs same height dynamically.
By jatrant in forum New To JavaReplies: 4Last Post: 06-25-2008, 08:09 PM -
ComboBox Fix Width
By Azndaddy in forum New To JavaReplies: 2Last Post: 05-29-2008, 04:23 AM -
dynamising the height of a JPopupMenu
By iimasd in forum AWT / SwingReplies: 6Last Post: 11-21-2007, 10:01 AM -
how to retrieve the width of the column
By katie in forum New To JavaReplies: 1Last Post: 08-06-2007, 10:56 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks