java中如何获取图像_在没有ImageObserver的情况下在Java中获取图像...

我试图在没有ImageObserver的情况下在Java中获取图像的高度和宽度(通过URL).

我目前的代码是:

public static void main(String[] args) throws IOException {

// TODO Auto-generated method stub

File xmlImages = new File("C:\images.xml");

BufferedReader br = new BufferedReader(new FileReader(xmlImages));

File output = new File("C:\images.csv");

BufferedWriter bw = new BufferedWriter(new FileWriter(output));

StringBuffer sb = new StringBuffer();

String line = null;

String newline = System.getProperty("line.separator");

while((line = br.readLine()) != null){

if(line.contains("http")){

URL url = new URL(line.)

Image img = Toolkit.getDefaultToolkit().getImage(url);

sb.append(line + ","+ img.getHeight(null) + "," + img.getWidth(Null) + newline);

}

}

br.close();

bw.write(sb.toString());

bw.close();

}

当我进入调试模式时,我能够看到图像已加载,我可以看到图像的高度和宽度,但我似乎无法返回它们. getHeight()和getWidth()方法需要一个我没有的Image Observer.先感谢您.

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

Powered By Z-BlogPHP 1.7.3

Copyright www.122dh.com Rights Reserved.