Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

image height&width needed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)?
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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



sorry my friend , This doesn't work
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic