List of utility methods to do ImageIcon
ImageIcon | fitToSquare(ImageIcon icon, int newSize) Scale an image to fit in a square of the given size, preserving aspect ratio. if (newSize <= 0) { return icon; final int oldWidth = icon.getIconWidth(); final int oldHeight = icon.getIconHeight(); int newWidth; int newHeight; if (oldHeight >= oldWidth) { ... |
ImageIcon | generateImageIcon(Color color, int size, Insets insets) generate Image Icon BufferedImage image = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = image.createGraphics(); g2d.setColor(color); if (insets != null) { g2d.fillRect(insets.left, insets.top, size - insets.left - insets.right, size - insets.top - insets.bottom); g2d.dispose(); ... |
ImageIcon | getBorderedIcon(ImageIcon icon) get Bordered Icon int borderWidth = 1 / 4; int spaceAroundIcon = 0; Color borderColor = Color.BLACK; BufferedImage bi = new BufferedImage(icon.getIconWidth() + (2 * borderWidth + 2 * spaceAroundIcon), icon.getIconHeight() + (2 * borderWidth + 2 * spaceAroundIcon), BufferedImage.TYPE_INT_ARGB); Graphics2D g = bi.createGraphics(); g.setColor(borderColor); g.drawImage(icon.getImage(), borderWidth + spaceAroundIcon, borderWidth + spaceAroundIcon, null); ... |
byte[] | getByteImage(ImageIcon icon) Convert a BufferedImage object to a byte[] stream if (icon == null) { throw new IllegalArgumentException("null 'image' argument."); final BufferedImage bi = getBufferedImage(icon); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); ImageIO.write(bi, "png", bos); return bos.toByteArray(); |
ImageIcon | getDisabledIcon(ImageIcon icon) Replies the disabled (grayed) version of the specified icon. return new ImageIcon(getDisabledImage(icon.getImage())); |
int | getHeight(ImageIcon imagen) Obtiene el alto de un IconImage return imagen.getIconHeight();
|
ImageIcon | getOpenSwingImage(String name, ImageIcon defaultIcon) get Open Swing Image ImageIcon icon = null; try { java.net.URL url = ClassLoader.getSystemResource("com/sunking/swing/images/" + name); icon = new ImageIcon(url); } catch (Exception ex) { if (icon == null || icon.getImageLoadStatus() != MediaTracker.COMPLETE || icon.getIconHeight() <= 0) { icon = defaultIcon; ... |
RenderedImage | getRenderedImage(ImageIcon icon) get Rendered Image RenderedImage image; if (icon.getImage() instanceof RenderedImage) { image = (RenderedImage) icon.getImage(); } else { image = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_3BYTE_BGR); Graphics2D g = ((BufferedImage) image).createGraphics(); icon.paintIcon(null, g, 0, 0); return image; |
long | getSizeOfImage(ImageIcon imgIn) get Size Of Image return (long) (imgIn.getIconHeight() * imgIn.getIconWidth() * 3); |
ImageIcon | getThumbImage(ImageIcon myLoadedImageIcon, int thumbHeight, int thumbWidth) get Thumb Image Image myImage = myLoadedImageIcon.getImage(); BufferedImage thumbImage = new BufferedImage(thumbWidth, thumbHeight, BufferedImage.TYPE_INT_RGB); Graphics2D graphics2D = thumbImage.createGraphics(); graphics2D.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); graphics2D.drawImage(myImage, 0, 0, thumbWidth, thumbHeight, null); graphics2D.dispose(); return new ImageIcon(thumbImage); |