如何在java中获取图像的大小 [英] how to get the size of an image in java

查看:130
本文介绍了如何在java中获取图像的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
我在java中使用Jtidy解析器。

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).getImage();
int imgWidth = image.getWidth(null);
int imgHeight = image.getHeight(null);






以上代码工作正常,我越来越高&安培;宽度正确。但我想看一个图像的大小(例如它是以KB还是以MB为单位)。请帮助我,如何获得图像的大小。是否有任何方法。


Above code is working fine,I am getting height & width properly.But I want to see the size of an image (for example whether it is in KB,or in MB ).Please help me,how to get the size of an image.Is there any method.

推荐答案

这是查找图像尺寸的最简单方法之一。

This is one of the simplest method to find the dimensions of image.

 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中获取图像的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆