Display BMP in JLabel
Asked Answered
G

2

6

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

Gentlewoman answered 27/2, 2009 at 7:21 Comment(0)
G
2

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.

Gentlewoman answered 27/2, 2009 at 8:41 Comment(0)
S
10

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.

Sumner answered 27/2, 2009 at 7:47 Comment(3)
ImageIO.read(imageFile) is returning null when the image is a bmp fileGentlewoman
There's no built-in BMP support until Java 5.Drouin
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..Edouard
G
2

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.

Gentlewoman answered 27/2, 2009 at 8:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.