Example usage for javax.imageio ImageWriter getOriginatingProvider

List of usage examples for javax.imageio ImageWriter getOriginatingProvider

Introduction

In this page you can find the example usage for javax.imageio ImageWriter getOriginatingProvider.

Prototype

public ImageWriterSpi getOriginatingProvider() 

Source Link

Document

Returns the ImageWriterSpi object that created this ImageWriter , or null if this object was not created through the IIORegistry .

Usage

From source file:org.lavajug.streamcaster.server.Server.java

/**
 *
 * @param args//from  www  .j a v  a  2s .c  om
 */
public static void main(String[] args) {
    int port = 7777;
    if (args.length > 0) {
        try {
            port = Integer.parseInt(args[0]);
        } catch (NumberFormatException ex) {
            showHelp();
            System.out.println(ex.getLocalizedMessage());
            System.exit(1);
        }
    }

    if (args.length > 1) {
        try {
            Configuration.load(args[1]);
        } catch (ParseException ex) {
            showHelp();
            System.out.println(ex.getLocalizedMessage());
            System.exit(1);
        }
    }

    Iterator<ImageWriter> iterator = ImageIO.getImageWritersByFormatName("png");
    while (iterator.hasNext()) {
        ImageWriter next = iterator.next();
        System.err.println(next.getOriginatingProvider().getDescription(Locale.getDefault()));
    }

    WebServer webServer = WebServers.createWebServer(port);
    webServer.add("/socket", new StreamWebsocketHandler());
    webServer.add("/resources/.*", new ResourcesHandler());
    webServer.add("/.*", new WebHandler());
    webServer.uncaughtExceptionHandler(new ExceptionsHandler());
    webServer.start();
}

From source file:ImageIOTest.java

/**
 * Gets a set of "preferred" format names of all image writers. The preferred format name is the
 * first format name that a writer specifies.
 * @return the format name set/* w w w  .j a  va 2 s.c o  m*/
 */
public static Set<String> getWriterFormats() {
    TreeSet<String> writerFormats = new TreeSet<String>();
    TreeSet<String> formatNames = new TreeSet<String>(Arrays.asList(ImageIO.getWriterFormatNames()));
    while (formatNames.size() > 0) {
        String name = formatNames.iterator().next();
        Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(name);
        ImageWriter writer = iter.next();
        String[] names = writer.getOriginatingProvider().getFormatNames();
        String format = names[0];
        if (format.equals(format.toLowerCase()))
            format = format.toUpperCase();
        writerFormats.add(format);
        formatNames.removeAll(Arrays.asList(names));
    }
    return writerFormats;
}

From source file:ImageIOTest.java

/**
 * Save the current image in a file/*from  w  w  w . j a  v a  2s  .  c o m*/
 * @param formatName the file format
 */
public void saveFile(final String formatName) {
    if (images == null)
        return;
    Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(formatName);
    ImageWriter writer = iter.next();
    JFileChooser chooser = new JFileChooser();
    chooser.setCurrentDirectory(new File("."));
    String[] extensions = writer.getOriginatingProvider().getFileSuffixes();
    chooser.setFileFilter(new FileNameExtensionFilter("Image files", extensions));

    int r = chooser.showSaveDialog(this);
    if (r != JFileChooser.APPROVE_OPTION)
        return;
    File f = chooser.getSelectedFile();
    try {
        ImageOutputStream imageOut = ImageIO.createImageOutputStream(f);
        writer.setOutput(imageOut);

        writer.write(new IIOImage(images[0], null, null));
        for (int i = 1; i < images.length; i++) {
            IIOImage iioImage = new IIOImage(images[i], null, null);
            if (writer.canInsertImage(i))
                writer.writeInsert(i, iioImage, null);
        }
    } catch (IOException e) {
        JOptionPane.showMessageDialog(this, e);
    }
}