/** * Paints the component as a PNG image to the supplied output stream * * @param c the component to capture as a PNG image * @param stream the stream to write the PNG data to */ public static void writeToStream(Component c, OutputStream stream) { writeToStream(c, "png", stream); }
/** * Writes a JPEG image of the supplied component to the given file. In particular, you can use this method to take a * 'screen shot' of a Chart component as a JPEG Image. * * @param c the component to save as an image * @param file the file to save it to * @throws FileNotFoundException if the file exists but is a directory rather than a regular file, does not exist * but cannot be created, or cannot be opened for any other reason */ public static void writeJpegToFile(Component c, File file) throws FileNotFoundException { FileOutputStream fos = new FileOutputStream(file); writeToStream(c, "jpg", fos); try { fos.close(); } catch (IOException e) { Logger.getAnonymousLogger().severe(e.getMessage()); } }
/** * Writes a GIF image of the supplied component to the given file. In particular, you can use this method to take a * 'screen shot' of a Chart component as a GIF Image. * * @param c the component to save as an image * @param file the file to save it to * @throws FileNotFoundException if the file exists but is a directory rather than a regular file, does not exist * but cannot be created, or cannot be opened for any other reason */ public static void writeGifToFile(Component c, File file) throws FileNotFoundException { FileOutputStream fos = new FileOutputStream(file); writeToStream(c, "gif", fos); try { fos.close(); } catch (IOException e) { Logger.getAnonymousLogger().severe(e.getMessage()); } }
/** * Writes a PNG image of the supplied component to the given file. In particular, you can use this method to take a * 'screen shot' of a Chart component as a PNG Image. * * @param c the component to save as an image * @param file the file to save it to * @throws FileNotFoundException if the file exists but is a directory rather than a regular file, does not exist * but cannot be created, or cannot be opened for any other reason */ public static void writePngToFile(Component c, File file) throws FileNotFoundException { FileOutputStream fos = new FileOutputStream(file); writeToStream(c, "png", fos); try { fos.close(); } catch (IOException e) { Logger.getAnonymousLogger().severe(e.getMessage()); } }