【问题标题】:Converting a ImageIcon array to a BufferedImage将 ImageIcon 数组转换为 BufferedImage
【发布时间】:2012-09-21 15:27:58
【问题描述】:

我想知道是否有办法将 ImageIcon[] 转换为一系列缓冲图像,我在想这样的事情:

  public BufferedImage iconArrayToBufferedImage(ImageIcon[] icon){
    for (int i = 0; i < icon.length; i++) {
        BufferedImage screenShot = new BufferedImage(icon[i]);
    }


    return screenShot;

}

【问题讨论】:

  • 您的目标是水平、垂直还是二维布局?还是您的目标是创建一组缓冲图像,每个图像图标一个?

标签: java arrays bufferedimage imageicon


【解决方案1】:

例如如this answer 所示。

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

对于许多图标,循环执行。

【讨论】:

  • 可行,但有没有办法将多个图像连接在一起,形成一个 BufferedImage?
  • 当然,它只需要一点逻辑(使最终图像更大,循环小图像)并在正确的位置绘制图像部分(查看paintIcon 的参数)。
猜你喜欢
  • 2013-02-09
  • 1970-01-01
  • 1970-01-01
  • 2020-02-16
  • 1970-01-01
  • 2012-12-14
  • 1970-01-01
  • 2013-08-10
  • 1970-01-01
相关资源
最近更新 更多