我想读取位于我的包中的图像的完整路径以缩放它,以便图像适合我的JLabel,但是,每次编译我的代码时都会产生以下错误:
javax.imageio.IIOException:无法读取输入文件! 在javax.imageio.ImageIO.read(未知来源)
代码:
public void loadImage(){
BufferedImage img = null;
try {
img = ImageIO.read(new File("/myPackage/image.jpg"));
} catch (IOException e) {
e.printStackTrace();
}
BufferedImage dimg = (BufferedImage) img.getScaledInstance(lblImage.getWidth(), lblImage.getHeight(),
Image.SCALE_SMOOTH);
ImageIcon imageIcon = new ImageIcon(dimg);
lblImage.setIcon(imageIcon);
contentPane.add(lblImage);
}
提前致谢! :)