Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有更好的方法可以将容器中的 JLabel 图标作为 BufferedImage 而不进行多次转换?
Component[] components = container.getComponents(); BufferedImage image = ((BufferedImage) ((ImageIcon) ((JLabel) components[i]).getIcon()).getImage());
为了从 JLabel 获取缓冲图像,您执行以下操作(这是您最初的答案所要求的):
Icon icon = label.getIcon(); BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(),BufferedImage.TYPE_INT_RGB);