我要取得宽高的图片在:WebRoot/images/icon.gif ,我的一个按比例缩小图片的类在:src/com/card/Image_WH.java下面,请问在这个类中怎么取得 icon.gif 的原始宽、高? 我的Image_WH.java是这么写的:
ImageIcon image=new ImageIcon(imgPath);
int width=image.getIconWidth();
int height=image.getIconHeight();这里的"imgPath"需要传进去一个相对路径"images/icon.gif",但是不对,请各位高手指点一下,还有其它的方式吗?
ImageIcon image=new ImageIcon(imgPath);
int width=image.getIconWidth();
int height=image.getIconHeight();这里的"imgPath"需要传进去一个相对路径"images/icon.gif",但是不对,请各位高手指点一下,还有其它的方式吗?
String s = "../imgs/3b81665cbd2351a1b8c68de1c64c776a.gif";
ImageIcon icon = new ImageIcon(s);
System.out.println(icon.getIconHeight());
System.out.println(icon.getIconWidth());
我这样写就可以,不知道你的是什么错。
将图片和SRC目录放在一起 然后String s = "imgs/3b81665cbd2351a1b8c68de1c64c776a.gif";
即可
对于你的目录不正确 可以用File file=new File("../imgs/3b81665cbd2351a1b8c68de1c64c776a.gif")
然后再输出file,可以看到你的绝对路径肯定是不正确的
可以加MSN:[email protected]