Results 1 to 11 of 11
  1. #1
    neeraj.singh is offline Member
    Join Date
    Feb 2009
    Location
    Delhi
    Posts
    63
    Rep Power
    0

    Default 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

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    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.

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    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.

  4. #4
    neeraj.singh is offline Member
    Join Date
    Feb 2009
    Location
    Delhi
    Posts
    63
    Rep Power
    0

    Default

    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

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Quote Originally Posted by neeraj.singh View Post
    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
    Read response #2 again. And this time, really read it.

    db

  6. #6
    neeraj.singh is offline Member
    Join Date
    Feb 2009
    Location
    Delhi
    Posts
    63
    Rep Power
    0

    Default

    wt is imageIO? how to use it?

  7. #7
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default

    Quote Originally Posted by neeraj.singh View Post
    wt is imageIO? how to use it?
    Nothing I've ever come across. Java is case sensitive.

    db

  8. #8
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    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.

  9. #9
    neeraj.singh is offline Member
    Join Date
    Feb 2009
    Location
    Delhi
    Posts
    63
    Rep Power
    0

    Default

    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
    /\/

  10. #10
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Follow the advice Steve gave. Is there a reason you're ignoring him? ImageIO works with URLs, files, jar files, etc.

  11. #11
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    7

    Default 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,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

Similar Threads

  1. Replies: 2
    Last Post: 03-01-2011, 01:30 AM
  2. Replies: 4
    Last Post: 06-25-2008, 08:09 PM
  3. ComboBox Fix Width
    By Azndaddy in forum New To Java
    Replies: 2
    Last Post: 05-29-2008, 04:23 AM
  4. dynamising the height of a JPopupMenu
    By iimasd in forum AWT / Swing
    Replies: 6
    Last Post: 11-21-2007, 10:01 AM
  5. how to retrieve the width of the column
    By katie in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 10:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •