List of utility methods to do Icon to Image
Image | iconImage(Icon icon) Transforms icon into an image.
if (icon instanceof ImageIcon) return ((ImageIcon) icon).getImage(); return null; |
Image | iconToImage(@Nonnull Component context, @Nullable final Icon icon) icon To Image if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); final int width = icon == null ? 16 : icon.getIconWidth(); final int height = icon == null ? 16 : icon.getIconHeight(); final BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); if (icon != null) { final Graphics g = image.getGraphics(); ... |
Image | iconToImage(Icon icon) icon To Image if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); icon.paintIcon(null, image.getGraphics(), 0, 0); return image; |
Image | iconToImage(Icon icon) icon To Image if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); } else { Graphics2D g = null; try { BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().createCompatibleImage(icon.getIconWidth(), icon.getIconHeight()); g = image.createGraphics(); ... |
Image | iconToImage(Icon icon) icon To Image if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); } else { int w = icon.getIconWidth(); int h = icon.getIconHeight(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); ... |
BufferedImage | iconToImage(Icon icon) Converts a Icon into a BufferedImage BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = image.createGraphics(); icon.paintIcon(null, g, 0, 0); g.dispose(); return image; |
BufferedImage | iconToImage(Icon icon) Convert the given icon to an image. BufferedImage ret = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); icon.paintIcon(new JLabel(), ret.createGraphics(), 0, 0); return ret; |
Image | iconToImage(Icon icon) icon To Image if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); } else { int w = icon.getIconWidth(); int h = icon.getIconHeight(); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); GraphicsConfiguration config = device.getDefaultConfiguration(); ... |
Image | iconToImage(Icon icon) icon To Image if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); } else { int w = icon.getIconWidth(); int h = icon.getIconHeight(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); ... |
Image | iconToImage(Icon icon) icon To Image if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); } else { BufferedImage image = createCompatibleTranslucentImage(icon.getIconWidth(), icon.getIconHeight()); Graphics2D g = image.createGraphics(); icon.paintIcon(null, g, 0, 0); g.dispose(); return image; ... |