Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
296 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...