Question
I'm working on a map editor for a simple map builder.
My idea was to paint walls in the map as black pixels, everything else (white colour) is free space in a room.
Any .jar to read bmp files ? So as to avoid the header, etc?
update
Im reading about Image4j
Thanks in adavance.
Solution
If you want to use Image4j, that's a pretty easy way to go. This code will display a bmp in a JLabel.
BufferedImage image = null;
try
{
image = BMPDecoder.read(new File("C:\\test.bmp"));
}
catch(IOException ex)
{
Logger.getLogger(DesktopApplication1View.class.getName()).log(Level.SEVERE, null, ex);
}
jLabel1.setIcon(new ImageIcon(image));
OTHER TIPS
I'd recommend you also look at the Java Advanced Imaging API Image I/O sub-project. The project Javadoc indicates that there is support (mostly in raster mode) for BMP files.
import javax.imageio.ImageIO;
class ListImageReaders {
public static void main(String[] args) {
String[] imageReaders = ImageIO.getReaderFileSuffixes();
for (String imageReader : imageReaders) {
System.out.println(imageReader);
}
}
}
Gives output (under Java 1.6)
bmp
jpg
wbmp
jpeg
png
gif
Press any key to continue . . .
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow