嗨 我在 java 中使用 Jtidy 解析器。
URL url = new URL("http://l1.yimg.com/t/frontpage/baba-ramdev-310511-60.jpg");
Image image = new ImageIcon(url).getImage();
int imgWidth = image.getWidth(null);
int imgHeight = image.getHeight(null);
上面的代码工作正常,我正在正确获取高度和宽度。但是我想查看图像的大小(例如它是以 KB 还是以 MB 为单位)。请帮助我,如何获取大小图像的。有什么方法吗。
最佳答案
这是找到图像尺寸的最简单方法之一。
URL url=new URL("Any web image url");
BufferedImage image = ImageIO.read(url);
int height = image.getHeight();
int width = image.getWidth();
System.out.println("Height : "+ height);
System.out.println("Width : "+ width);
关于java - java获取图片大小的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6250200/