Reputation: 1
I am new to swing. I was trying the game tutorial by wilchit sombat on making of packman. I cannot view the BufferedImage
. Here is the code which overrides some methods from the game engine.
package game.packman;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import org.Game.Engine.Game;
import org.Game.Engine.GameApplication;
public class PackMan extends Game {
public static void main(String args[]) {
GameApplication.start(new PackMan());
}
BufferedImage packman;
public PackMan() {
title = "PACKMAN";
width = height = 400;
try {
packman = ImageIO.read(new File("images/pacmanimg.xcf"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Override
public void init() {
// TODO Auto-generated method stub
}
@Override
public void update() {
// TODO Auto-generated method stub
}
@Override
public void draw(Graphics g) {
g.drawImage(packman, 100, 100, null);
}
}
Upvotes: 0
Views: 176
Reputation: 57421
Check size of the image packman
after loaing
packman = ImageIO.read(new File("images/pacmanimg.xcf"));
It's 0 width/height if the image is not loaded.
Anyway it's better to place the image in your classpath and use getResourceAsStream() to load it through ImageIO. In opposite case when you pack your code in a jar you need to resolve working with files and relative paths problem.
Upvotes: 0
Reputation: 15428
Image I/O
has built-in support for GIF, PNG, JPEG, BMP, and WBMP
. Image I/O is also extensible so that developers or administrators can "plug-in" support for additional formats. For example, plug-ins for TIFF
and JPEG 2000
are separately available.
So, it seems that XCF
: native image format of the GIMP
image-editing program, is not supported by ImageIO
.
Reference:
Upvotes: 4