/** * Returns a {@link List} of supported output formats. * * @return A {@link List} of supported output formats. If no formats * are supported, an empty list is returned. */ public static List<String> getSupportedOutputFormats() { String[] formats = ImageIO.getWriterFormatNames(); if (formats == null) { return Collections.emptyList(); } else { return Arrays.asList(formats); } }
/** * Constructor initializes formats for alternative file names to protect from unintentionally * overwriting existing files. */ public ImageHandler() { super(); // Create a HashSet to quickly check for supported extensions. extensions = new HashSet<>(); Collections.addAll(extensions, ImageIO.getWriterFormatNames()); }
/** * Returns a sorted array of format names, that can be written by ImageIO. * The names are all upper-case, and contains no duplicates. * * @return a normalized array of {@code String}s. * @see javax.imageio.ImageIO#getWriterFormatNames() */ public static String[] getNormalizedWriterFormatNames() { return normalizeNames(ImageIO.getWriterFormatNames()); }
String[] writers = ImageIO.getWriterFormatNames();
String[] writerFormatNames = ImageIO.getWriterFormatNames(); for (String fmt : writerFormatNames)
/** * Test if a given image output format name is supported * * @param fmt * the format name * @return true if supported; false otherwise */ public static boolean isWriteFormatSupported(String fmt) { return ArrayUtils.contains(ImageIO.getWriterFormatNames(), fmt); }
/** * Test if a given image output format name is supported * * @param fmt * the format name * @return true if supported; false otherwise */ public static boolean isWriteFormatSupported(String fmt) { return ArrayUtils.contains(ImageIO.getWriterFormatNames(), fmt); }
private boolean isImageFormatSupported(String imageFormat) { String writerNames[] = ImageIO.getWriterFormatNames(); for(String writerFormat : writerNames) { if (writerFormat.equalsIgnoreCase(imageFormat)) { return true; } } return false; }
private static List<String> lookupAvailableImageFormat() { List<String> extensions = new ArrayList<String>(); for (int i = 0; i < ImageIO.getWriterFormatNames().length; i++) { String ext = ImageIO.getWriterFormatNames()[i].toLowerCase(); if(!extensions.contains(ext)) extensions.add(ext); } return extensions; }
public static void listSupportedFormats() { System.out.println( MessageFormat.format(rb.getString("formats"), Arrays.toString(ImageIO.getWriterFormatNames()))); } }
public BitmapExporter(String extension, double scale) { this.extension = extension; this.scale = scale; boolean match = false; String[] formats = ImageIO.getWriterFormatNames(); for (int i = 0; i < formats.length; i++) { if (formats[i].equals(extension)) { match = true; break; } } if (!match) throw new IllegalArgumentException("Format " + extension + " is not supported by the ImageIO class"); }
/** * Returns a {@link List} of supported output formats. * * @return A {@link List} of supported output formats. If no formats * are supported, an empty list is returned. */ public static List<String> getSupportedOutputFormats() { String[] formats = ImageIO.getWriterFormatNames(); if (formats == null) { return Collections.emptyList(); } else { return Arrays.asList(formats); } }
public void initialize() { String[] names = ImageIO.getWriterFormatNames(); boolean supportsGif = false; for (int i=0; i < names.length; i++) { if (names[i].toLowerCase().equals("gif")) { supportsGif = true; break; } } if (!supportsGif) { _nonTransparentFormatName = "jpeg"; } }
/** * Test if the image output format suggested by the extension of the given * filename is supported * * @param file * the file * @return true if supported; false otherwise */ public static boolean isWriteFormatSupported(File file) { final String name = file.getName(); String format = name.substring(name.lastIndexOf(".") + 1); format = format.toLowerCase().trim(); return ArrayUtils.contains(ImageIO.getWriterFormatNames(), format); } }
/** * Test if the image output format suggested by the extension of the given * filename is supported * * @param file * the file * @return true if supported; false otherwise */ public static boolean isWriteFormatSupported(File file) { final String name = file.getName(); String format = name.substring(name.lastIndexOf(".") + 1); format = format.toLowerCase().trim(); return ArrayUtils.contains(ImageIO.getWriterFormatNames(), format); } }
/** * Returns a sorted array of format names, that can be written by ImageIO. * The names are all upper-case, and contains no duplicates. * * @return a normalized array of {@code String}s. * @see javax.imageio.ImageIO#getWriterFormatNames() */ public static String[] getNormalizedWriterFormatNames() { return normalizeNames(ImageIO.getWriterFormatNames()); }
/** * List the available formats that can be rendered. * * @return supported formats */ public final List<String> listFormats() { final List<String> formats = new ArrayList<>(); formats.add(SVG_FMT); formats.add(SVG_FMT.toUpperCase(Locale.ROOT)); formats.add(PS_FMT); formats.add(PS_FMT.toUpperCase(Locale.ROOT)); formats.add(EPS_FMT); formats.add(EPS_FMT.toUpperCase(Locale.ROOT)); formats.add(PDF_FMT); formats.add(PDF_FMT.toUpperCase(Locale.ROOT)); formats.addAll(Arrays.asList(ImageIO.getWriterFormatNames())); return formats; }
/** * List the available formats that can be rendered. * * @return supported formats */ public final List<String> listFormats() { final List<String> formats = new ArrayList<>(); formats.add(SVG_FMT); formats.add(SVG_FMT.toUpperCase(Locale.ROOT)); formats.add(PS_FMT); formats.add(PS_FMT.toUpperCase(Locale.ROOT)); formats.add(EPS_FMT); formats.add(EPS_FMT.toUpperCase(Locale.ROOT)); formats.add(PDF_FMT); formats.add(PDF_FMT.toUpperCase(Locale.ROOT)); formats.addAll(Arrays.asList(ImageIO.getWriterFormatNames())); return formats; }
public void valueChanged(ListSelectionEvent e) { String type = (String) ((JList) e.getSource()).getSelectedValue(); spinner.setEnabled(false); for (String scalabletype : ImageIO.getWriterFormatNames()) { if (type.equals(scalabletype)) { spinner.setEnabled(true); return; } } } });
@Test public void testname() throws Exception { System.out.println(Arrays.asList(ImageIO.getReaderMIMETypes())); System.out.println(Arrays.asList(ImageIO.getWriterFormatNames())); System.out.println(Arrays.asList(ImageIO.getReaderFormatNames())); URL pngFile = getClass().getResource("/test.png"); BufferedImage img = ImageIO.read(pngFile); for (String type : ImageIO.getWriterFormatNames()) { if (type.equalsIgnoreCase("jpg") || type.equalsIgnoreCase("jpeg")) { // Avoid issue #6 on OpenJDK8/Debian continue; } File f = File.createTempFile("imageio-test", "." + type); ImageIO.write(img, type, f); System.out.println(f); ImageIO.read(f); } }