如何获取图片的宽度?
public class Test { public static void main(String[] args) { Toolkit tk = Toolkit.getDefaultToolkit(); Image image1 = tk.getImage("f:/TestDir/test.jpg"); int width1 = image1.getWidth(null); System.out.println(width1); }}
public class Test2 { public static void main(String[] args) { Toolkit tk = Toolkit.getDefaultToolkit(); Image image1 = tk.getImage("f:/TestDir/test.jpg"); Image image2 = new ImageIcon("f:/TestDir/test.jpg").getImage(); int width1 = image1.getWidth(null); System.out.println(width1); int width2 = image2.getWidth(null); System.out.println(width2); }}