List of utility methods to do Icon to Image
Image | iconToImage(Icon icon) Converts an Icon to an Image. if (icon instanceof ImageIcon) { return ((ImageIcon) icon).getImage(); 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 { int w = icon.getIconWidth(); int h = icon.getIconHeight(); GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); ... |
BufferedImage | iconToImage(Icon icon, Component comp) icon To Image int width = icon.getIconWidth(); int height = icon.getIconHeight(); if (width <= 0 || height <= 0) { return null; BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); icon.paintIcon(comp, g, 0, 0); ... |
Image | iconToImage(Icon icon, int width, int height) icon To Image int w = icon.getIconWidth(); int h = icon.getIconHeight(); boolean sameSize = w == width && h == height; if (icon instanceof ImageIcon && sameSize) { return ((ImageIcon) icon).getImage(); } else { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); ... |