将ImageIcon转换为BufferedImage

我一直在尝试将ImageIcon转换为BufferedImage ……而且我没有运气。

我有一个预先存在的ImageIcon,需要转换为缓冲图像,用于存在的大量BufferedImage操作。

我找到了几种方法,但它们都是CPU密集型的。

出了什么问题:

 BufferedImage bi = new BufferedImage( icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); // paint the Icon to the BufferedImage. icon.paintIcon(null, g, 0,0); g.dispose(); 

请参见ImageIcon , Image和BufferedImage :

 ImageIcon yourImage; Image image = yourImage.getImage(); BufferedImage buffered = (BufferedImage) image; 

我尝试了一些名为Scalr的东西,查看下面的代码

Scalr.resize((BufferedImage) ImageIO.read(file), Method.SPEED, 250, OP_ANTIALIAS, OP_BRIGHTER);

干杯。