Issue displaying PNG file
I seem to have an issue displaying "some" PNG files. I am using the source code from Brakeen's tile game in his book. I have converted from using ImageIcon to ImageIO as my way of reading in images. Specifically, I have used the code snippet from Abuse about loading images so that they are accelerated. I can get the game to run fine.
I have started porting the code so that I can write my own game. I took a bmp file that I wanted to use as a spalsh screen and converted it to a PNG file using MS Paint. When I try to display that as my splash page, ImageIO.read throws an IllegalArgumentException. Here are the main code snippets that get an image:
public URL getResource( String filename ) {
return getClass().getClassLoader().getResource( filename );
}
/**
* Gets an image from the images/ directory.
*/
public BufferedImage loadImage( String name ) {
String filename = "images/" + name;
BufferedImage ret = null;
try {
System.out.println( filename );
System.out.println( this.getResource( filename ) );
BufferedImage src = ImageIO.read( this.getResource( filename ) );
// Images returned from ImageIO are NOT managed images. Therefore,
// we copy it into a managed image.
ret = gc.createCompatibleImage( src.getWidth(), src.getHeight(), src.getColorModel().getTransparency() );
Graphics2D g2d = (Graphics2D) ret.getGraphics();
g2d.setComposite( AlphaComposite.Src );
g2d.drawImage( src, 0, 0, null );
g2d.dispose();
} catch( IOException ioe ) {
ioe.printStackTrace();
// ignore so that this method returns null
}
return ret;
}
I added in the System.out.println and see that when I request my new PNG file, that the URL returned is null which leads to the issue with ImageIO.read. If I change my splash screen back to the JPG that Brakeen uses, it displays the image fine. I tried converting the JPG to a PNG using MS Paint and get the same issue that I received with my PNG file. I am positive that I have them in the right directory because I simply saved Brakeen's image in the same directory with a PNG extension and changed my source code from .jpg to .png. It appears that the getResource method is returning null for the two PNG files that I created yet returns a proper URL for other PNG files that I got from Brakeen.
I have searched the forums for the last hour and do not see anything that matches my problem. I even tried moving the images into a res folder that I saw in one post to no avail. I am running Windows XP if that has any bearing on this. I can only think that somehow I have bad stuff in the PNG files. However, when I click my two PNG files, they are properly displayed in Windows.
Any help would be greatly appreciated.

