List of utility methods to do Image
BufferedImage | renderComponentToImage(JComponent component) Renders a component into an image, which is useful for playing with the component's resultant image in special effects or transitions BufferedImage image = createCompatibleImage(component.getWidth(), component.getHeight());
Graphics graphics = image.createGraphics();
component.paint(graphics);
graphics.dispose();
return image;
|
void | save(Image image, File file, String formatName) save FileOutputStream os = new FileOutputStream(file);
ImageIO.write(toBufferedImage(image), formatName, os);
|
void | saveComponentAsImage(final String path, final Component target, final String format) Given a component, saves it on disk as image. final JFrame win = (JFrame) SwingUtilities.getWindowAncestor(target); final Dimension size = win.getSize(); final BufferedImage image = (BufferedImage) win.createImage(size.width, size.height); final Graphics g = image.getGraphics(); win.paint(g); g.dispose(); ImageIO.write(image, format, new File(path)); |
void | SaveImageToFile(Image img, String filename, String outformat) Save Image To File BufferedImage bimg = ScaleToSize(img, -1, -1); if (outformat.equalsIgnoreCase("JPEG") || outformat.equalsIgnoreCase("JPG")) SaveJPEG(bimg, new File(filename)); else SaveImageToFile(bimg, filename, outformat); |
BufferedImage | scaleBarcodeMaxWidth(Image i, int width, int cropHeigth) Scales if Image is wider, Crops if image is higer. BufferedImage ret; int newWidth; int newHeigth; boolean scale; boolean crop; int iWidth = i.getWidth(null); int iHeigth = i.getHeight(null); if (iWidth == -1 || iWidth > width) { ... |
boolean | setImage(Image im, JComponent c) Ensures that Images is completely loaded boolean b = true; MediaTracker mt = new MediaTracker(c); mt.addImage(im, 0); try { mt.waitForID(0); } catch (InterruptedException e) { System.out.println("Error while image loading."); b = false; ... |
void | setImageDimension(Image imagen) Establece las dimensiones de una imagen widthImage = new ImageIcon(imagen).getIconWidth(); heightImage = new ImageIcon(imagen).getIconHeight(); |
void | showImage(final String title, final Image image) show Image EventQueue.invokeLater(new Runnable() { @Override public void run() { try { JFrame jFrame = new JFrame(title); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.add(new JLabel(new ImageIcon(image))); jFrame.pack(); ... |
void | showImage(Image image) show Image createImageFrame(image).setVisible(true); |
void | showImage(Image image, String title) Show image in a JFrame. JFrame frame = new JFrame(title); JLabel label = new JLabel(new ImageIcon(image)); frame.getContentPane().add(label); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setVisible(true); |