当前位置: 技术问答>java相关
高手请进,小问题寻求解答!
来源: 互联网 发布时间:2015-11-16
本文导语: private void loadBoardImage(String name) { BufferedImage boardImage =null; Image loadedImage= Toolkit.getDefaultToolkit().getImage(name); MediaTracker tracker = new MediaTracker(this); tracker.addImage(loadedImage, 0); try { ...
private void loadBoardImage(String name) {
BufferedImage boardImage =null;
Image loadedImage= Toolkit.getDefaultToolkit().getImage(name);
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(loadedImage, 0);
try {
tracker.waitForID(0);
}
catch (InterruptedException e) {
System.out.print(e.getMessage());
}
boardImage = new BufferedImage(loadedImage.getWidth (
null),loadedImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = boardImage.createGraphics();
g2.drawImage(loadedImage, 0, 0, null);
}
上面的方法编译时没错,但是为什么有些文件能画,有些图象文件不能画呢?(注:文件格式没有错,全是.jpg文件)
BufferedImage boardImage =null;
Image loadedImage= Toolkit.getDefaultToolkit().getImage(name);
MediaTracker tracker = new MediaTracker(this);
tracker.addImage(loadedImage, 0);
try {
tracker.waitForID(0);
}
catch (InterruptedException e) {
System.out.print(e.getMessage());
}
boardImage = new BufferedImage(loadedImage.getWidth (
null),loadedImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
Graphics2D g2 = boardImage.createGraphics();
g2.drawImage(loadedImage, 0, 0, null);
}
上面的方法编译时没错,但是为什么有些文件能画,有些图象文件不能画呢?(注:文件格式没有错,全是.jpg文件)
|
看你的错误代码,觉得是
boardImage = new BufferedImage(loadedImage.getWidth (null), loadedImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
这句话有错,getXXX(null)大概返回了-1的值。而在建新的BufferedImage对象的时候应该不能把负数值传给它的。
boardImage = new BufferedImage(loadedImage.getWidth (null), loadedImage.getHeight(null), BufferedImage.TYPE_INT_RGB);
这句话有错,getXXX(null)大概返回了-1的值。而在建新的BufferedImage对象的时候应该不能把负数值传给它的。
|
up一下
|
up
|
help