如何在JFrame中显示BufferedImage?
-
06-07-2019 - |
题
我想在同一个JFrame中显示同一图像的变体,例如在JFrame中显示图像,然后用相同图像的灰度替换它。
解决方案
其他提示
基于camickr的解决方案(对于像我这样想要快速复制/粘贴代码的懒人),这里有一个代码说明:
JFrame frame = new JFrame();
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(new JLabel(new ImageIcon(img)));
frame.getContentPane().add(new JLabel(new ImageIcon(img2)));
frame.getContentPane().add(new JLabel(new ImageIcon(img3)));
frame.pack();
frame.setVisible(true);
//frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // if you want the X button to close the app
我不确定你的问题但是如果你有一个BufferedImage,那么你只需使用图像创建一个ImageIcon,然后将图标添加到JLabel并像其他任何组件一样将标签添加到GUI。 / p>
如果您质疑如何创建灰度,我建议您使用这些字词作为搜索关键字搜索网页,我相信您会在那里找到示例。
不隶属于 StackOverflow