Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

image height&width needed

 
sujendra sugur
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi


i need the code which can calculate image dimensions before uploading into server.

based on size i have to upload into server.

the fallowing code i tried but it works fine on my local machine and stucks when i put same code in server.




private BufferedImage getImage(String filename)
{
BufferedImage image = null;
File file = new File(filename);

try{
if(file.exists()){

image = ImageIO.read(file);

}
}
catch(Exception ex){
ex.printStackTrace();
}
return image;
}


if(image!=null && image.getWidth() == 478 && image.getHeight() == 476){

albumPhotoPaths.add(localPath);

}


can any body suggest the better code than this and i tried pixel grabber and Toolkit tool = Toolkit.getDefaultToolkit().getImage () methods also but the result is same.


thank you
sujendra
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java's java.awt.Image class comes with accessor methods for both width and height. Have you looked at them? Alternatively you can do much the same from an javax.swing.ImageIcon. Assuming you are doing this from an Applet you can use either.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can you calculate the size of an image in Java before uploading the image to the place where the Java runs (on the server)?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ImageInfo class is very useful for such purposes: http://linux.wareseeker.com/Multimedia/imageinfo-1.9.zip/322196
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Newton wrote:How can you calculate the size of an image in Java before uploading the image to the place where the Java runs (on the server)?


In an Applet?
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
image.getWidth() == 478 && image.getHeight() == 476


sorry my friend , This doesn't work
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Sturrock wrote:
David Newton wrote:How can you calculate the size of an image in Java before uploading the image to the place where the Java runs (on the server)?


In an Applet?

(Well yeah, but it was more a rhetorical question, since so far I haven't heard this is an applet.)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic