Display BMP in JLabel

后端 未结 2 872
清歌不尽
清歌不尽 2020-12-18 05:40

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 Imag         


        
2条回答
  •  悲&欢浪女
    2020-12-18 05:52

    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.

提交回复
热议问题