Display BMP in JLabel
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.
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, 2022Comments
-
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
inJava
1.4
?Thanks
-
Markus Lausberg over 15 yearsImageIO.read(imageFile) is returning null when the image is a bmp file
-
user482594 over 12 yearsI 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..