File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get Image height and width

 
ramnna jain
Ranch Hand
Posts: 129
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to get image size before I dynamically set it as background to a div object
so that, I can set height & width of the div accordingly.

I tried:





It worked fine with mozilla but not with IE.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this.
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In my html page I have one div tag with id 'somediv'.

On page load I want to set the div size, which is the size of the image.
To do this I created a new Image object & set the size of the div.
After setting the div size to the size of the image I set the image as background of the div object.
(Please see the above code.)

When I tried the code with Mozilla, the div get the size of the image.
But when I tried the same with Internet Explorer: The div is set to the size of the image.
But when I tried the same with different image sizes, in some cases the div did not take the size of the image.
This faulty behavior seldom happens, but I want it to completely resolve.

I am trying my code on Windows XP SP2, IE 6.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am guessing it has not loaded fully when you read the width and height. Try



Eric
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Eric... I am getting the desired results. Thank you again.
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above mentioned problem was all because I named the jpg file 'bp.jpg'.

The problem is identified when tried with IE6.

When you name the file bp.jpg and try it with above mentioned code, and try to print
using . In IE6 it shows the wrong size.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The name of the image has nothing to do with the width and height.

If you get a value that is different, are you sure it is not using a cached version of the file?

Eric
 
ramnna jain
Ranch Hand
Posts: 129
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In IE6 I cleared all the cache: Internet Options - General tab (Delete Cookies, Delete Files & Clear History).

I closed the Browser & restart it and tried the same. It is strange to see that when
I changed the names of different file to 'bp', and tried the results were same, erroneous.

I don't know what is the reason! But may be it is similar to try to create folder naming 'con',
which is a reserved word and we can't create one with this name.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic