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

Urgent: Need to know the size of Image Uploaded

 
daman sidhu
Ranch Hand
Posts: 184
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,
I have an application where i upload a image through a web page to the server and put it in the database, i need to check that the image is of particualr height and width only and then only insert in the DB else show error. I tried it by converting the bytes as below but got -1 as height and width.
This coding is in the servlet class:
// f is the file object uploaded.
byte [] b=new byte[(int)f.length()];
fis.read(b);
System.out.println("after file read");
// this is the code to check the file length
Toolkit toolKit=Toolkit.getDefaultToolkit();
Image image=toolKit.createImage(b);
int width=image.getWidth(null);
int heigth=image.getHeight(null);
System.out.println("Height is "+heigth+" Width is "+width);
***************
I get both as -1
I will be very thankful if anyone can help me out in this.
Regards,
Daman

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic