将ImageIcon转换为BufferedImage

时间:2013-02-24 15:24:29

标签: java bufferedimage imageicon

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

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

我找到了一些方法,但所有这些方法都非常耗费CPU。

3 个答案:

答案 0 :(得分:31)

出了什么问题:

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();

答案 1 :(得分:8)

请参阅ImageIconImageBufferedImage

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

答案 2 :(得分:-2)

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

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

干杯。

相关问题