Show BMP in JLabel

Java can display png, jpg some other image formats, but I need to display the BMP file in JLable, getting the file path.

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

ImageIcon supports typical png,gif,jpg images.

I am working in a project, I cannot open the bmp file and save the same file as jpg, because I cannot store something at runtime. I could only generate an image by holding it in my memory. But I do not know how to do this.

How can I show BMP in Java 1.4 ?

thanks

+6
java image bmp
source share
2 answers

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

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

You get a BMP converter that works very well.

+2
source share

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.

+8
source share

All Articles