将ImageIcon转换为BufferedImage [英] Converting an ImageIcon to a BufferedImage

查看:325
本文介绍了将ImageIcon转换为BufferedImage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been trying to convert a ImageIcon to BufferedImage... And I've had no luck.

我有一个预先存在的ImageIcon,对于存在的大量BufferedImage操作,需要将其转换为Buffered Image.

I have a pre-existing ImageIcon that needs to be converted to a Buffered Image for the vast amount of BufferedImage operations that exist.

我已经找到了几种方法,但是所有方法都占用大量CPU.

I have found a few ways, but all of them are hugely CPU intensive.

推荐答案

出了什么问题:

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转换为BufferedImage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆