Converting an ImageIcon to a BufferedImage

♀尐吖头ヾ 提交于 2019-11-29 03:59:09

What's wrong with:

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

See ImageIcon, Image and BufferedImage:

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

I tried something called Scalr, view the code below

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

Cheers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!