Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Read bmp files?

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.

like image 808
Tom Avatar asked Feb 13 '26 23:02

Tom


2 Answers

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));
like image 63
Arnold Spence Avatar answered Feb 15 '26 12:02

Arnold Spence


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.

like image 25
mlschechter Avatar answered Feb 15 '26 11:02

mlschechter