我尝试了 getScaledInstance 之类的方法,但都不起作用。我也无法在网上找到任何解决方案。我目前使用的代码是:
public class ShowImage_1 extends Panel {
BufferedImage image;
public ShowImage_1() {
try {
File input = new File("C:/Lighthouse.jpg");
image = ImageIO.read(input);
image.getGraphics().drawImage(image, 0, 0, 400, 400, null);
} catch (IOException ie) {
System.out.println("Error:" + ie.getMessage());
}
}
public void paint(Graphics g) {
g.drawImage(image, 0, 0, null);
}
static public void main(String args[]) throws Exception {
JFrame frame = new JFrame("Display image");
Panel panel = new ShowImage_1();
frame.getContentPane().add(panel);
frame.pack();
frame.setVisible(true);
}
}
它不会在面板上显示完整图像。关于如何去做的任何想法?
我想达到这个效果:http: //img209.imageshack.us/i/77894822.png/
但我现在得到的是:http: //img600.imageshack.us/i/19267006.png/
我可以使用任何其他代码来获得它吗?