Wednesday, December 21, 2011

How to get width and height of an image in Java

Following method can be used to get width and height of jpg, gif, or png file
import javax.swing.ImageIcon;

public void printSize(){
  ImageIcon jpegImage = new
  ImageIcon("C:\\Users\\prageethj\\Desktop\\cute.jpg");
  int height = jpegImage.getIconHeight();
  int width = jpegImage.getIconWidth();
  System.out.println(width + "x" + height);
}

No comments:

Post a Comment