gpt4 book ai didi

java - java获取图片大小的方法

转载 作者:搜寻专家 更新时间:2023-10-30 21:19:38 26 4
gpt4 key购买 nike

嗨 我在 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com