List of utility methods to do BufferedImage Load
Image | loadFromResource(String imageName, Class cls) Loads an Image named imageName as a resource relative to the Class cls .
try { final URL url = cls.getResource(imageName); if (url == null) { return null; Image image = (Image) imageCache.get(url.toString()); if (image == null) { image = Toolkit.getDefaultToolkit().createImage(url); ... |
BufferedImage | loadFromURL(String url) load From URL try { return ImageIO.read(new URL(url)); } catch (IOException e) { e.printStackTrace(); return null; |
BufferedImage | loadImage(byte[] data) load Image BufferedImage img = null; try (InputStream input = new ByteArrayInputStream(data)) { img = ImageIO.read(input); return img; |
BufferedImage | loadImage(ClassLoader classLoader, String path) load Image try { URL url = classLoader.getResource(path); if (url != null) { return ImageIO.read(url); } else { return null; } catch (IOException e) { ... |
BufferedImage | loadImage(File file) Load an image from a file using ImageIO. ImageInputStream is = ImageIO.createImageInputStream(file); Iterator<ImageReader> iter = ImageIO.getImageReaders(is); if (!iter.hasNext()) { throw new IOException("Unsupported file format."); ImageReader imageReader = iter.next(); imageReader.setInput(is); return imageReader.read(0); ... |
BufferedImage | loadImage(File file) Loads image from the file. try { return ImageIO.read(file); } catch (IOException ex) { throw new RuntimeException("IOException whle trying to load image file" + file.getName(), ex); |
BufferedImage | loadImage(File file) load Image final FileInputStream fis = new FileInputStream(file); try { final BufferedImage bufferedImage = ImageIO.read(fis); if (bufferedImage == null) { throw new IOException("ImageIO.read returned null for " + file); return bufferedImage; } finally { ... |
BufferedImage | loadImage(File file) load Image BufferedImage bi = null; try { bi = ImageIO.read(file); } catch (IOException e) { e.printStackTrace(); return bi; |
BufferedImage | loadImage(File pFile) load Image BufferedImage im = ImageIO.read(pFile); GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice device = env.getDefaultScreenDevice(); GraphicsConfiguration config = device.getDefaultConfiguration(); BufferedImage buffy = config.createCompatibleImage(im.getWidth(), im.getHeight(), im.getTransparency()); Graphics2D g2d = buffy.createGraphics(); setupGraphics(g2d); g2d.drawImage(im, 0, 0, null); ... |
BufferedImage | loadImage(final byte[] imageData) Uses javax.imageio.ImageIO to read the specified data into a java.awt.image.BuffededImage .
final ByteArrayInputStream in = new ByteArrayInputStream(imageData); final BufferedImage bi = ImageIO.read(in); in.close(); return bi; |