List of utility methods to do ImageIcon Load
ImageIcon | getImageIcon(String path, String description) Returns an ImageIcon, or null if the path was invalid. if (path == null || path.trim().length() == 0) { throw new IllegalArgumentException("Invalid file path: " + path); URL imgURL = ClassLoader.getSystemResource(path); if (imgURL != null) { return new ImageIcon(imgURL, description); throw new IllegalArgumentException("Couldn't find file: " + path); ... |
ImageIcon | getImageIcon(String res) Retrieves an ImageIcon from the specified resource try { return new ImageIcon(ClassLoader.getSystemResource(res)); } catch (Exception e) { e.printStackTrace(); return null; |
ImageIcon | getImageIcon(String resource) get Image Icon URL imageURL = ClassLoader.getSystemResource(resource); ImageIcon image = new ImageIcon(imageURL); return image; |
ImageIcon | getImageIcon(URL u, int w) get Image Icon BufferedImage img = null; BufferedImage tmp = ImageIO.read(u); ImageIcon icon = null; if (tmp != null) { float h = (float) tmp.getHeight() * (float) w / (float) tmp.getWidth(); img = scaleImage(w, (int) h, tmp, RenderingHints.VALUE_INTERPOLATION_BICUBIC); icon = new ImageIcon((Image) img); return icon; |
ImageIcon | getImageIcon(URL url) get Image Icon ImageIcon icon = (url == null) ? null : (new ImageIcon(url)); return icon; |
Image | getScaledInstance(Image img, int targetWidth, int targetHeight) Redimensionne une image. final int type = BufferedImage.TYPE_INT_ARGB; Image ret = img; final int width = ret.getWidth(null); final int height = ret.getHeight(null); if (width != targetWidth && height != targetHeight) { final BufferedImage scratchImage = new BufferedImage(targetWidth, targetHeight, type); final Graphics2D g2 = scratchImage.createGraphics(); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR); ... |
ImageIcon | loadImageIcon(byte bytes[], String descr) load Image Icon ImageIcon image = new ImageIcon(bytes, descr); return image; |
ImageIcon | loadImageIcon(Class clas, String iconPath) Loads a icon from either the file system or from a jar. ImageIcon icon = null; URL url = clas.getResource(iconPath); if (url != null) { icon = new ImageIcon(url); return icon; |
ImageIcon | loadImageIcon(String imageName) Loads an image from a given path and returns it as an ImageIcon. return new ImageIcon(loadImage(imageName)); |
ImageIcon | loadImageIcon(String url) load Image Icon byte[] data = getResourceAsBytes(url); ImageIcon icon = new ImageIcon(data); return icon; |