how to get the size of an image in java

后端 未结 4 1477
谎友^
谎友^ 2021-02-03 11:14

hi I am using Jtidy parser in java.


URL url = new URL(\"http://l1.yimg.com/t/frontpage/baba-ramdev-310511-60.jpg\");  
Image image = new ImageIcon(url).g         


        
4条回答
  •  情书的邮戳
    2021-02-03 11:50

    Try:

    url.openConnection().getContentLength();
    

    If this doesn't work, you can load the stream using:

    url.openStream()
    

    ...and read the stream until the end, counting how many bytes were actually read. You might also use CountingInputStream decorator to reuse the stream later. However the first code snippet seems to work.

提交回复
热议问题