我需要找到一種方法來計算圖像的長度和寬度(這是一個.jpg)我有文件的長度,但它沒有用,因爲我想創建一個數組來存儲有關每個我正在使用的圖像文件的像素。如何在java中獲得jpg的像素尺寸?
public void getImageData(){
File f= new File("myPicture.jpg");
this.length = (int) f.length();
System.out.println("length of file = " + length);
BufferedImage image = null;
try {
image = ImageIO.read(f);
}
catch (IOException e) {
e.printStackTrace();
}
非常感謝!
可能的重複http://stackoverflow.com/questions/1559253/java-imageio-getting-image-dimension-without-reading-the-entire-file – 2012-07-11 20:51:46