Java Code Examples for javax.imageio.ImageIO#getWriterFormatNames()

The following examples show how to use javax.imageio.ImageIO#getWriterFormatNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConverterTest.java    From healthcare-dicom-dicomweb-adapter with Apache License 2.0 6 votes vote down vote up
@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);
	}
}
 
Example 2
Source File: DCTPluginTemplate.java    From openstego with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method to get the list of supported file extensions for writing
 *
 * @return List of supported file extensions for writing
 * @throws OpenStegoException
 */
@Override
public List<String> getWritableFileExtensions() throws OpenStegoException {
    if (writeFormats != null) {
        return writeFormats;
    }

    String format = null;
    String[] formats = null;
    List<String> formatList = new ArrayList<String>();

    formats = ImageIO.getWriterFormatNames();
    for (int i = 0; i < formats.length; i++) {
        format = formats[i].toLowerCase();
        if (format.indexOf("jpeg") >= 0 && format.indexOf("2000") >= 0) {
            format = "jp2";
        }
        if (!formatList.contains(format)) {
            formatList.add(format);
        }
    }

    Collections.sort(formatList);
    writeFormats = formatList;
    return writeFormats;
}
 
Example 3
Source File: WMImagePluginTemplate.java    From openstego with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method to get the list of supported file extensions for writing
 *
 * @return List of supported file extensions for writing
 * @throws OpenStegoException
 */
@Override
public List<String> getWritableFileExtensions() throws OpenStegoException {
    if (writeFormats != null) {
        return writeFormats;
    }

    String format = null;
    String[] formats = null;
    writeFormats = new ArrayList<String>();

    formats = ImageIO.getWriterFormatNames();
    for (int i = 0; i < formats.length; i++) {
        format = formats[i].toLowerCase();
        if (format.indexOf("jpeg") >= 0 && format.indexOf("2000") >= 0) {
            format = "jp2";
        }
        if (!writeFormats.contains(format)) {
            writeFormats.add(format);
        }
    }

    Collections.sort(writeFormats);
    return writeFormats;
}
 
Example 4
Source File: DHImagePluginTemplate.java    From openstego with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method to get the list of supported file extensions for writing
 *
 * @return List of supported file extensions for writing
 * @throws OpenStegoException
 */
@Override
public List<String> getWritableFileExtensions() throws OpenStegoException {
    if (writeFormats != null) {
        return writeFormats;
    }

    String format = null;
    String[] formats = null;
    writeFormats = new ArrayList<String>();

    formats = ImageIO.getWriterFormatNames();
    for (int i = 0; i < formats.length; i++) {
        format = formats[i].toLowerCase();
        if (format.indexOf("jpeg") >= 0 && format.indexOf("2000") >= 0) {
            format = "jp2";
        }
        if (!writeFormats.contains(format)) {
            writeFormats.add(format);
        }
    }

    Collections.sort(writeFormats);
    return writeFormats;
}
 
Example 5
Source File: ThumbnailatorUtils.java    From youkefu with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
	}
}
 
Example 6
Source File: GetReaderWriterInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testGetWriterFormatNames() {
    String[] names = ImageIO.getWriterFormatNames();
    for (String n : names) {
        Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName(n);
        if (!it.hasNext()) {
            throw new RuntimeException("getWriterFormatNames returned " +
                                       "an unknown name: " + n);
        }
    }
}
 
Example 7
Source File: ImageUtil.java    From Knowage-Server with GNU Affero General Public License v3.0 5 votes vote down vote up
synchronized private static String getFormatName(String filename) throws IOException {
	String ext = filename.substring(filename.lastIndexOf(".") + 1);
	String[] arr = ImageIO.getWriterFormatNames();
	for (int i = 0; i < arr.length; i++) {
		if (arr[i].equals(ext))
			return ext;
	}
	throw new IOException("file [" + filename + "] has a format not supported [" + ext + "]");
}
 
Example 8
Source File: GetReaderWriterInfo.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testGetWriterFormatNames() {
    String[] names = ImageIO.getWriterFormatNames();
    for (String n : names) {
        Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName(n);
        if (!it.hasNext()) {
            throw new RuntimeException("getWriterFormatNames returned " +
                                       "an unknown name: " + n);
        }
    }
}
 
Example 9
Source File: FileChooserDemo.java    From littleluck with Apache License 2.0 5 votes vote down vote up
public FilePreview() {
    super(1, 0, 1);

    for (String s : ImageIO.getWriterFormatNames()) {
        knownTypes.put(s.toLowerCase(), FileType.IMAGE);
    }

    initUI();
}
 
Example 10
Source File: FileChooserDemo.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
public FilePreview() {
    super(1, 0, 1);

    for (String s : ImageIO.getWriterFormatNames()) {
        knownTypes.put(s.toLowerCase(), FileType.IMAGE);
    }

    initUI();
}
 
Example 11
Source File: FileChooserDemo.java    From Darcula with Apache License 2.0 5 votes vote down vote up
public FilePreview() {
    super(1, 0, 1);

    for (String s : ImageIO.getWriterFormatNames()) {
        knownTypes.put(s.toLowerCase(), FileType.IMAGE);
    }

    initUI();
}
 
Example 12
Source File: FileChooserDemo.java    From littleluck with Apache License 2.0 4 votes vote down vote up
private void initUI() {
    externalChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPEG images", "jpg"));
    externalChooser.addChoosableFileFilter(new FileNameExtensionFilter("All supported images",
            ImageIO.getWriterFormatNames()));

    final FilePreview filePreview = new FilePreview();

    externalChooser.setAccessory(filePreview);
    externalChooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY,
            new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    filePreview.loadFileInfo(externalChooser.getSelectedFile());
                }
            });

    embeddedChooser.setControlButtonsAreShown(false);

    embeddedChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPEG images", "jpg"));

    FileNameExtensionFilter filter = new FileNameExtensionFilter("All supported images",
            ImageIO.getWriterFormatNames());

    embeddedChooser.addChoosableFileFilter(filter);
    embeddedChooser.setFileFilter(filter);

    for (int i = MIN_FILTER_ID; i <= MAX_FILTER_ID; i++) {
        cbFilters.addItem(new FilterItem(i, resourceManager.getString(FILTER_NAMES[i])));
    }

    JGridPanel pnFilter = new JGridPanel(2, 0);

    pnFilter.cell(cbFilters).
            cell(btnApplyFilter);

    JGridPanel pnRotateButtons = new JGridPanel(4, 3);

    pnRotateButtons.cell(btnRotateLeft).
            cell(btnRotateRight).
            cell(btnFlipHorizontal).
            cell(btnFlipVertical);

    JGridPanel pnBottom = new JGridPanel(4, 1);

    pnBottom.setHGap(JGridPanel.DEFAULT_GAP * 4);

    pnBottom.cell(btnSelect, JGridPanel.Layout.FILL).
            cell().
            cell(pnFilter).
            cell(btnSave, JGridPanel.Layout.FILL).
            cell(btnSelectWithPreview, JGridPanel.Layout.FILL).
            cell().
            cell(pnRotateButtons).
            cell(btnCancel, JGridPanel.Layout.FILL);

    pnContent.cell(pnImage);
    pnContent.cell(pnBottom, new Insets(10, 10, 10, 10));

    add(pnContent);

    setState(State.EMPTY, false);
}
 
Example 13
Source File: FileChooserDemo.java    From beautyeye with Apache License 2.0 4 votes vote down vote up
private void initUI() {
    externalChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPEG images", "jpg"));
    externalChooser.addChoosableFileFilter(new FileNameExtensionFilter("All supported images",
            ImageIO.getWriterFormatNames()));

    final FilePreview filePreview = new FilePreview();

    externalChooser.setAccessory(filePreview);
    externalChooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY,
            new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    filePreview.loadFileInfo(externalChooser.getSelectedFile());
                }
            });

    embeddedChooser.setControlButtonsAreShown(false);

    embeddedChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPEG images", "jpg"));

    FileNameExtensionFilter filter = new FileNameExtensionFilter("All supported images",
            ImageIO.getWriterFormatNames());

    embeddedChooser.addChoosableFileFilter(filter);
    embeddedChooser.setFileFilter(filter);

    for (int i = MIN_FILTER_ID; i <= MAX_FILTER_ID; i++) {
        cbFilters.addItem(new FilterItem(i, resourceManager.getString(FILTER_NAMES[i])));
    }

    JGridPanel pnFilter = new JGridPanel(2, 0);

    pnFilter.cell(cbFilters).
            cell(btnApplyFilter);

    JGridPanel pnRotateButtons = new JGridPanel(4, 3);

    pnRotateButtons.cell(btnRotateLeft).
            cell(btnRotateRight).
            cell(btnFlipHorizontal).
            cell(btnFlipVertical);

    JGridPanel pnBottom = new JGridPanel(4, 1);

    pnBottom.setHGap(JGridPanel.DEFAULT_GAP * 4);

    pnBottom.cell(btnSelect, JGridPanel.Layout.FILL).
            cell().
            cell(pnFilter).
            cell(btnSave, JGridPanel.Layout.FILL).
            cell(btnSelectWithPreview, JGridPanel.Layout.FILL).
            cell().
            cell(pnRotateButtons).
            cell(btnCancel, JGridPanel.Layout.FILL);

    pnContent.cell(pnImage);
    pnContent.cell(pnBottom, new Insets(10, 10, 10, 10));

    add(pnContent);

    setState(State.EMPTY, false);
}
 
Example 14
Source File: ImageLoadJaiTest.java    From java-image-processing-survival-guide with Apache License 2.0 4 votes vote down vote up
/**
 * List available image formats.
 * see http://examples.javacodegeeks.com/desktop-java/imageio/list-read-write-supported-image-formats/
 */
@Test
public void testListSupportedImageFormats() throws Exception {

    Set<String> set = new HashSet<String>();

    // Get list of all informal format names understood by the current set of registered readers
    String[] formatNames = ImageIO.getReaderFormatNames();

    for (int i = 0; i < formatNames.length; i++) {
        set.add(formatNames[i].toLowerCase());
    }
    System.out.println("Supported read formats: " + set);

    set.clear();

    // Get list of all informal format names understood by the current set of registered writers
    formatNames = ImageIO.getWriterFormatNames();

    for (int i = 0; i < formatNames.length; i++) {
        set.add(formatNames[i].toLowerCase());
    }
    System.out.println("Supported write formats: " + set);

    set.clear();

    // Get list of all MIME types understood by the current set of registered readers
    formatNames = ImageIO.getReaderMIMETypes();

    for (int i = 0; i < formatNames.length; i++) {
        set.add(formatNames[i].toLowerCase());
    }
    System.out.println("Supported read MIME types: " + set);

    set.clear();

    // Get list of all MIME types understood by the current set of registered writers
    formatNames = ImageIO.getWriterMIMETypes();

    for (int i = 0; i < formatNames.length; i++) {
        set.add(formatNames[i].toLowerCase());
    }
    System.out.println("Supported write MIME types: " + set);
}
 
Example 15
Source File: FileChooserDemo.java    From Darcula with Apache License 2.0 4 votes vote down vote up
private void initUI() {
    externalChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPEG images", "jpg"));
    externalChooser.addChoosableFileFilter(new FileNameExtensionFilter("All supported images",
            ImageIO.getWriterFormatNames()));

    final FilePreview filePreview = new FilePreview();

    externalChooser.setAccessory(filePreview);
    externalChooser.addPropertyChangeListener(JFileChooser.SELECTED_FILE_CHANGED_PROPERTY,
            new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent evt) {
                    filePreview.loadFileInfo(externalChooser.getSelectedFile());
                }
            });

    embeddedChooser.setControlButtonsAreShown(false);

    embeddedChooser.addChoosableFileFilter(new FileNameExtensionFilter("JPEG images", "jpg"));

    FileNameExtensionFilter filter = new FileNameExtensionFilter("All supported images",
            ImageIO.getWriterFormatNames());

    embeddedChooser.addChoosableFileFilter(filter);
    embeddedChooser.setFileFilter(filter);

    for (int i = MIN_FILTER_ID; i <= MAX_FILTER_ID; i++) {
        cbFilters.addItem(new FilterItem(i, resourceManager.getString(FILTER_NAMES[i])));
    }

    JGridPanel pnFilter = new JGridPanel(2, 0);

    pnFilter.cell(cbFilters).
            cell(btnApplyFilter);

    JGridPanel pnRotateButtons = new JGridPanel(4, 3);

    pnRotateButtons.cell(btnRotateLeft).
            cell(btnRotateRight).
            cell(btnFlipHorizontal).
            cell(btnFlipVertical);

    JGridPanel pnBottom = new JGridPanel(4, 1);

    pnBottom.setHGap(JGridPanel.DEFAULT_GAP * 4);

    pnBottom.cell(btnSelect, JGridPanel.Layout.FILL).
            cell().
            cell(pnFilter).
            cell(btnSave, JGridPanel.Layout.FILL).
            cell(btnSelectWithPreview, JGridPanel.Layout.FILL).
            cell().
            cell(pnRotateButtons).
            cell(btnCancel, JGridPanel.Layout.FILL);

    pnContent.cell(pnImage);
    pnContent.cell(pnBottom, new Insets(10, 10, 10, 10));

    add(pnContent);

    setState(State.EMPTY, false);
}