Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display BMP in JLabel

Tags:

java

image

bmp

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

like image 617
Markus Lausberg Avatar asked Feb 27 '09 07:02

Markus Lausberg


2 Answers

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.

like image 179
Peter Walser Avatar answered Sep 22 '22 06:09

Peter Walser


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.

like image 34
Markus Lausberg Avatar answered Sep 24 '22 06:09

Markus Lausberg