1

I need to find a way to work out the length and the width of the image (which is a .jpg) I have the length of the file but it is not useful because I want to make an array to store information about each pixel of the image file I am using.

public void getImageData(){
    File f= new File("myPicture.jpg");
    this.length = (int) f.length();
        System.out.println("length of file = " + length);
        BufferedImage image = null;
        try {
            image = ImageIO.read(f);
            } 
        catch (IOException e) {

            e.printStackTrace();
            }

Help much appreciated!

Magpie
  • 607
  • 2
  • 7
  • 26
  • possible duplicate http://stackoverflow.com/questions/1559253/java-imageio-getting-image-dimension-without-reading-the-entire-file – John Moses Jul 11 '12 at 20:51

1 Answers1

4

Once you get the BufferedImage, you can just call the properties getWidth() and getHeight() on it:

int imageWidth = image.getWidth();
int imageHeight = image.getHeight();

Hope this helps.

Dan W
  • 5,718
  • 4
  • 33
  • 44
  • 1
    If an answer works, check the green check mark next to their answer so people know you've found a solution! – Wires77 Jul 11 '12 at 21:14