【发布时间】:2011-11-18 14:33:21
【问题描述】:
为什么下面的代码会返回 Height: -1 表示高度未知。如何获取图片的高度?
try {
// Create a URL for the image's location
URL url = new URL("http://bmw-2006.auto-one.co.uk/wp-content/uploads/bmw-m3-2006-3.jpg");
// Get the image
java.awt.Image image = Toolkit.getDefaultToolkit().createImage(url);
System.out.println("Height: " + image.getHeight(null));
} catch (MalformedURLException e) {
} catch (IOException e) {
}
【问题讨论】:
-
stackoverflow.com/questions/672916/… 的可能重复项 - 取决于是否需要使用 AWT Image 类。
-
@berry120 - 我想说的是 Java 不想看图像太久是个问题......
标签: java image asynchronous