my dog learned polymorphism*
The moose likes Servlets and the fly likes image height&width needed Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "image height&width needed" Watch "image height&width needed" New topic
Author

image height&width needed

sujendra sugur
Greenhorn

Joined: Mar 25, 2010
Posts: 12
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

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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
Marshal

Joined: Mar 22, 2005
Posts: 41816
    
  62
The ImageInfo class is very useful for such purposes: http://linux.wareseeker.com/Multimedia/imageinfo-1.9.zip/322196


Ping & DNS - my free Android networking tools app
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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

Joined: Apr 18, 2009
Posts: 2234

image.getWidth() == 478 && image.getHeight() == 476


sorry my friend , This doesn't work


Save India From Corruption - Anna Hazare.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: image height&width needed