我有这个奇怪的问题。我刚刚将所有图像从GIF转换为png,然后将我在代码中寻找的文件扩展名更改为png,现在控制台仍然被垃圾邮件发送:
Sun Feb 22 23:39:37 CST 2015 WARN:class org.newdawn.slick.opengl.PNGImageData>无法读取数据 java.lang.UnsupportedOperationException:此图像的格式不受支持 at org.newdawn.slick.opengl.PNGDecoder.decode(PNGDecoder.java:272) at org.newdawn.slick.opengl.PNGImageData.loadImage(PNGImageData.java:97) at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:62) at org.newdawn.slick.opengl.CompositeImageData.loadImage(CompositeImageData.java:43) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:292) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:254) at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:200) at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64) at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24) at helpers.Artist.LoadTexture(Artist.java:340) at helpers.Artist.QuickLoad(Artist.java:349) 在helpers.Artist.ClearScreen(Artist.java:73) at data.Boot。(Boot.java:87) 在data.Boot.main(Boot.java:155)
奇怪的是,图像都正确显示。我不知道为什么会这样。以下是尝试加载图片的代码:
public static Texture LoadTexture(String path, String fileType){
Texture tex=null;
InputStream in=ResourceLoader.getResourceAsStream(path);
try{
tex =TextureLoader.getTexture(fileType,in);
}catch(IOException e){
e.printStackTrace();
}
return tex;
}
public static Texture QuickLoad(String name){
Texture tex=null;
tex=LoadTexture("res/"+name+".png","PNG");
return tex;
}
有没有人知道发生了什么?如果需要,我会发布更多信息。
更新
我更改了代码,但是它给了我一条错误信息,然后程序关闭了。我不确定我做错了什么。
以下是代码:
public static Texture LoadTexture(String path, String fileType){
Texture texture=null;
try{
BufferedImage bufferedImage = ImageIO.read(new File(path));
texture = BufferedImageUtil.getTexture(fileType,bufferedImage);
}catch(IOException e){
e.printStackTrace();
}
return texture;
}
public static Texture QuickLoad(String name){
Texture tex=null;
tex=LoadTexture("res/"+name+".png","PNG");
return tex;
}
这是错误信息
javax.imageio.IIOException:无法读取输入文件! 在javax.imageio.ImageIO.read(未知来源) at helpers.Artist.LoadTexture(Artist.java:352) at helpers.Artist.QuickLoad(Artist.java:362) 在helpers.Artist.BeginSession(Artist.java:69) at data.Boot。(Boot.java:16) at data.Boot.main(Boot.java:155) javax.imageio.IIOException:无法读取输入文件! 在javax.imageio.ImageIO.read(未知来源) at helpers.Artist.LoadTexture(Artist.java:352) at helpers.Artist.QuickLoad(Artist.java:362) 在helpers.Artist.BeginSession(Artist.java:70) at data.Boot。(Boot.java:16) at data.Boot.main(Boot.java:155) javax.imageio.IIOException:无法读取输入文件! 在javax.imageio.ImageIO.read(未知来源) at helpers.Artist.LoadTexture(Artist.java:352) at helpers.Artist.QuickLoad(Artist.java:362) at data.MenuSelection。(MenuSelection.java:11) at data.Menu.createSelectionElements(Menu.java:80) at data.Menu.createMenu(Menu.java:22) at data.Menu.doMenuAction(Menu.java:283) at data.Boot。(Boot.java:81) at data.Boot.main(Boot.java:155) javax.imageio.IIOException:无法读取输入文件! 在javax.imageio.ImageIO.read(未知来源) at helpers.Artist.LoadTexture(Artist.java:352) at helpers.Artist.QuickLoad(Artist.java:362) at data.MenuSelection。(MenuSelection.java:12) at data.Menu.createSelectionElements(Menu.java:80) at data.Menu.createMenu(Menu.java:22) at data.Menu.doMenuAction(Menu.java:283) at data.Boot。(Boot.java:81) at data.Boot.main(Boot.java:155) javax.imageio.IIOException:无法读取输入文件! 在javax.imageio.ImageIO.read(未知来源) at helpers.Artist.LoadTexture(Artist.java:352) at helpers.Artist.QuickLoad(Artist.java:362) at helpers.Artist.ClearScreen(Artist.java:75) at data.Boot。(Boot.java:87) at data.Boot.main(Boot.java:155) 线程" main"中的例外情况显示java.lang.NullPointerException at helpers.Artist.ClearScreen(Artist.java:75) at data.Boot。(Boot.java:87) 在data.Boot.main(Boot.java:155)