List of utility methods to do Icon to BufferedImage
BufferedImage | getBufferedImage(Component comp, Icon icon) get Buffered Image if (icon instanceof ImageIcon) { Image img = ((ImageIcon) icon).getImage(); if (img instanceof BufferedImage) { return (BufferedImage) img; return createImage(comp, icon); |
BufferedImage | getBufferedImage(Icon icon) get Buffered Image if (icon instanceof BufferedImage) { return (BufferedImage) icon; BufferedImage bimage = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = bimage.createGraphics(); g.addRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY)); g.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); ... |
BufferedImage | getBufferedImageFromIcon(Icon icon) Creates a buffered image from an icon. BufferedImage buffer = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); Graphics g = buffer.getGraphics(); icon.paintIcon(new JLabel(), g, 0, 0); g.dispose(); return buffer; |
BufferedImage | iconToBufferedImage(Icon icon) icon To Buffered Image BufferedImage bi = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB); Graphics g = bi.createGraphics(); g.setColor(Color.WHITE); g.fillRect(0, 0, icon.getIconWidth(), icon.getIconHeight()); icon.paintIcon(null, g, 0, 0); return bi; |
BufferedImage | toBufferedImage(Icon icon) to Buffered Image BufferedImage result = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB); icon.paintIcon(null, result.createGraphics(), 0, 0); return result; |
BufferedImage | toBufferedImage(Icon icon, int x, int y) Converts the given Icon into a BufferedImage . if (icon != null) { Graphics2D g = null; try { BufferedImage image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), Transparency.TRANSLUCENT); g = image.createGraphics(); icon.paintIcon(null, g, x, y); return image; ... |