0

I'm downloading a photo from url address with the following code:

try(InputStream in = new URL(photoURL).openStream()){
    Files.copy(in, Paths.get("\\outputFiles\\photo.jpg"));
    System.out.println(outputDir+newPhotoURL);
}

But how can I additionaly display width and height of that image?

user3766930
  • 5,629
  • 10
  • 51
  • 104
  • @AxelH how can I create an image object first to get its width and height? – user3766930 Feb 10 '17 at 12:31
  • By reading the 11 answers of the duplicate question I have linked ? you have the file ... if this is a small image, create the ImageBuffered with it – AxelH Feb 10 '17 at 12:33

1 Answers1

1

You can use BufferedImage it has methods getHeight() & getWidth() in Java 7.

BufferedImage

Code for the same :

BufferedImage imo;
        try {
            imo = ImageIO.read(new File("location_of_file"));
            System.out.println(imo.getHeight());
            System.out.println(imo.getWidth());
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
prab2112
  • 1,024
  • 10
  • 36