用Java获取图像宽度和高度 [英] Get Image Width and Height in Java
本文介绍了用Java获取图像宽度和高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想问一下如何获取图像的宽度和高度,因为这会为宽度和高度返回-1:
I just want to ask how to get the width and height of an image, because this returns -1 for width and height:
private void resizeImage(Image image){
JLabel imageLabel = new JLabel();
int imageWidth = image.getWidth(null);
int imageHeight = image.getHeight(null);
System.out.println("Width:" + imageWidth);
System.out.println("Height:" + imageHeight);
}
推荐答案
你应该这样做:
BufferedImage bimg = ImageIO.read(new File(filename));
int width = bimg.getWidth();
int height = bimg.getHeight();
因此帖子说
这篇关于用Java获取图像宽度和高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文