简体   繁体   English

JLabel得到了图像

[英]JLabel get Image

Is there any better way to get the Icon of a JLabel in a container as a BufferedImage whithout multiple casts? 有没有更好的方法可以将容器中的JLabel的Icon作为BufferedImage获得多个转换?

Component[] components = container.getComponents();
BufferedImage image = ((BufferedImage) ((ImageIcon) ((JLabel) components[i]).getIcon()).getImage());

In order to get a buffered image from a JLabel, you do the following (which is what your original answer asked): 为了从JLabel获取缓冲图像,您可以执行以下操作(这是您的原始答案所要求的):

Icon icon = label.getIcon();
BufferedImage bi = new BufferedImage(icon.getIconWidth(),
                icon.getIconHeight(),BufferedImage.TYPE_INT_RGB);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM