Display BMP in JLabel

10,480

Solution 1

I find some classes written in Java 1.5 but you can easily update 2 classes so that you can use the classes in 1.4.

imag4j can convert bmp and ico files to BufferedImage objects you can display in java. You can import 17 classes and have to update maybe 10 lines because of java 1.5 statements.

You get a bmp converter which is working very fine.

Solution 2

javax.imageio.ImageIO supports the BMP format:

Image image = ImageIO.read(imageFile);
ImageIcon icon = new ImageIcon(image);

JLabel label = new JLabel(icon);

ImageIO can also be used to convert between different formats.

Share:
10,480
Markus Lausberg
Author by

Markus Lausberg

Software Developer, Automotive Applications. Software/Tools i am using: Eclipse Java C/C++ JavaScript SVN ANT Microsoft Project Sparx Systems - Enterprise Architect Polarion Profiler (JProfiler, JVisualVM, JMC) JetBrains - WebStorm Oxygen XML Editor

Updated on August 16, 2022

Comments

  • Markus Lausberg
    Markus Lausberg almost 2 years

    Java can display png, jpg a some other picture formats, but i have to display a bmp file in a JLable by getting the file path.

    ImageIcon imageIcon = new ImageIcon(imageFile.getAbsolutePath());
    

    ImageIcon support the typical png,gif,jpg images.

    In the project i am working, i can not open a bmp file and store the same file as a jpg, because i am not allow to store something at runtime. I could only generate the image in hold it in memory. But i dont know how to do this.

    How can i show BMP in Java 1.4?

    Thanks

  • Markus Lausberg
    Markus Lausberg over 15 years
    ImageIO.read(imageFile) is returning null when the image is a bmp file
  • user482594
    user482594 over 12 years
    I have been figuring out why my implementation was not working for few hours...and now I realize that loading bmp file directly does not work..