2

I have an image url like,

String url = "http://XXXXXXX/img_High-Octane-Sauce-Company-JP5-400x1024.jpg";

I need this to be take as an input to the method,

ImageInputStream in = ImageIO.createImageInputStream( urlInputHere );

so I can read the width and height of the image without using image buffer. Can anyone please tell me how to do this?

This is the way I am reading the image

ImageInputStream in = ImageIO.createImageInputStream(resourceFile);
try {
    final Iterator<ImageReader> readers = ImageIO.getImageReaders(in);
    if (readers.hasNext()) {
        ImageReader reader = readers.next();
        try {
            reader.setInput(in);
            return new Dimension(reader.getWidth(0), reader.getHeight(0));
        } finally {
            reader.dispose();
        }
    }
} finally {
    if (in != null) in.close();
}

P.S. Taken from : Java/ImageIO getting image dimensions without reading the entire file?

Community
  • 1
  • 1
Roshanck
  • 2,220
  • 8
  • 41
  • 56
  • Consider rewriting your question for clarity. – Paul Vargas Sep 05 '13 at 12:48
  • I need to read the image as the answer given in this question. http://stackoverflow.com/questions/1559253/java-imageio-getting-image-dimension-without-reading-the-entire-file But I have only a url of the image. don't know how to use it in here – Roshanck Sep 05 '13 at 12:50

1 Answers1

5

try this:

    String url = "http://XXXXXXX/img_High-Octane-Sauce-Company-JP5-400x1024.jpg";
    InputStream urlInputHere = new URL(url).openStream();
    ImageInputStream in = ImageIO.createImageInputStream( urlInputHere );
Claudiu
  • 1,469
  • 13
  • 21