java 在 JLabel 中显示 BMP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/593830/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Display BMP in JLabel
提问by Markus Lausberg
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.
Java 可以显示 png、jpg 和其他一些图片格式,但我必须通过获取文件路径在 JLable 中显示 bmp 文件。
ImageIcon imageIcon = new ImageIcon(imageFile.getAbsolutePath());
ImageIcon support the typical png,gif,jpgimages.
ImageIcon 支持典型png,gif,jpg图像。
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.
在我正在工作的项目中,我无法打开 bmp 文件并将相同的文件存储为 jpg,因为我不允许在运行时存储某些内容。我只能在内存中生成图像。但我不知道该怎么做。
How can i show BMPin Java1.4?
我怎样才能显示BMP在Java1.4?
Thanks
谢谢
采纳答案by Markus Lausberg
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.
我发现一些用 Java 1.5 编写的类,但您可以轻松更新 2 个类,以便您可以使用 1.4 中的类。
imag4jcan 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.
imag4j可以将 bmp 和 ico 文件转换为可以在 java 中显示的 BufferedImage 对象。由于 java 1.5 语句,您可以导入 17 个类,并且可能必须更新 10 行。
You get a bmp converter which is working very fine.
你会得到一个工作非常好的 bmp 转换器。
回答by Peter Walser
javax.imageio.ImageIOsupports the BMP format:
javax.imageio.ImageIO支持 BMP 格式:
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.
ImageIO 也可用于在不同格式之间进行转换。

