Example usage for javax.imageio ImageIO getReaderFormatNames

List of usage examples for javax.imageio ImageIO getReaderFormatNames

Introduction

In this page you can find the example usage for javax.imageio ImageIO getReaderFormatNames.

Prototype

public static String[] getReaderFormatNames() 

Source Link

Document

Returns an array of String s listing all of the informal format names understood by the current set of registered readers.

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String[] formatNames = ImageIO.getReaderFormatNames();
    System.out.println(Arrays.toString(formatNames));
}

From source file:Main.java

public static void main(String[] args) {
    String[] readers, writers;// w  ww.  j av  a2  s. c o m

    System.out.println("For Reading:");
    readers = ImageIO.getReaderFormatNames();
    System.out.println("\tBy format:");
    for (int i = 0; i < readers.length; i++)
        System.out.println("\t\t" + readers[i]);

    readers = ImageIO.getReaderMIMETypes();
    System.out.println("\tBy MIME Types:");
    for (int i = 0; i < readers.length; i++)
        System.out.println("\t\t" + readers[i]);

    System.out.println("For Writing:");
    writers = ImageIO.getWriterFormatNames();
    System.out.println("\tBy format:");
    for (int i = 0; i < writers.length; i++)
        System.out.println("\t\t" + writers[i]);

    writers = ImageIO.getWriterMIMETypes();
    System.out.println("\tBy MIME Types:");
    for (int i = 0; i < writers.length; i++)
        System.out.println("\t\t" + writers[i]);
}

From source file:ShowImageIOInfo.java

static public void main(String args[]) throws Exception {
    String names[] = ImageIO.getReaderFormatNames();
    for (int i = 0; i < names.length; ++i) {
        System.out.println("reader " + names[i]);
    }// w w w. ja v  a 2 s  .c  o  m

    names = ImageIO.getWriterFormatNames();
    for (int i = 0; i < names.length; ++i) {
        System.out.println("writer " + names[i]);
    }
}

From source file:ImageUtil.java

/**
 * get supported image format/*from   ww w  .java  2  s.  c om*/
 * @return supported image format array
 */
public static String[] getSupportedImageFormat() {
    return ImageIO.getReaderFormatNames();
}

From source file:ImageUtil.java

/**
 * check if image supported/*  w w w  .ja v  a 2 s  .c  om*/
 * @param extName extension name of image file
 * @return true supported, else false
 */
public static boolean isSupportedImage(String extName) {
    boolean isSupported = false;
    for (String format : ImageIO.getReaderFormatNames()) {
        if (format.equalsIgnoreCase(extName)) {
            isSupported = true;
            break;
        }
    }
    return isSupported;
}

From source file:info.magnolia.module.imaging.tools.ImageIOPluginsPage.java

public Collection<String> getInputFormatNames() {
    return filter(ImageIO.getReaderFormatNames());
}

From source file:com.chiorichan.factory.event.PostImageProcessor.java

@EventHandler()
public void onEvent(PostEvalEvent event) {
    try {/*from   w  w  w.ja  v  a  2  s.  co m*/
        if (event.context().contentType() == null
                || !event.context().contentType().toLowerCase().startsWith("image"))
            return;

        float x = -1;
        float y = -1;

        boolean cacheEnabled = AppConfig.get().getBoolean("advanced.processors.imageProcessorCache", true);
        boolean grayscale = false;

        ScriptingContext context = event.context();
        HttpRequestWrapper request = context.request();
        Map<String, String> rewrite = request.getRewriteMap();

        if (rewrite != null) {
            if (rewrite.get("serverSideOptions") != null) {
                String[] params = rewrite.get("serverSideOptions").trim().split("_");

                for (String p : params)
                    if (p.toLowerCase().startsWith("width") && x < 0)
                        x = Integer.parseInt(p.substring(5));
                    else if ((p.toLowerCase().startsWith("x") || p.toLowerCase().startsWith("w"))
                            && p.length() > 1 && x < 0)
                        x = Integer.parseInt(p.substring(1));
                    else if (p.toLowerCase().startsWith("height") && y < 0)
                        y = Integer.parseInt(p.substring(6));
                    else if ((p.toLowerCase().startsWith("y") || p.toLowerCase().startsWith("h"))
                            && p.length() > 1 && y < 0)
                        y = Integer.parseInt(p.substring(1));
                    else if (p.toLowerCase().equals("thumb")) {
                        x = 150;
                        y = 0;
                        break;
                    } else if (p.toLowerCase().equals("bw") || p.toLowerCase().equals("grayscale"))
                        grayscale = true;
            }

            if (request.getArgument("width") != null && request.getArgument("width").length() > 0)
                x = request.getArgumentInt("width");

            if (request.getArgument("height") != null && request.getArgument("height").length() > 0)
                y = request.getArgumentInt("height");

            if (request.getArgument("w") != null && request.getArgument("w").length() > 0)
                x = request.getArgumentInt("w");

            if (request.getArgument("h") != null && request.getArgument("h").length() > 0)
                y = request.getArgumentInt("h");

            if (request.getArgument("thumb") != null) {
                x = 150;
                y = 0;
            }

            if (request.hasArgument("bw") || request.hasArgument("grayscale"))
                grayscale = true;
        }

        // Tests if our Post Processor can process the current image.
        List<String> readerFormats = Arrays.asList(ImageIO.getReaderFormatNames());
        List<String> writerFormats = Arrays.asList(ImageIO.getWriterFormatNames());
        if (context.contentType() != null
                && !readerFormats.contains(context.contentType().split("/")[1].toLowerCase()))
            return;

        int inx = event.context().buffer().readerIndex();
        BufferedImage img = ImageIO.read(new ByteBufInputStream(event.context().buffer()));
        event.context().buffer().readerIndex(inx);

        if (img == null)
            return;

        float w = img.getWidth();
        float h = img.getHeight();
        float w1 = w;
        float h1 = h;

        if (x < 1 && y < 1) {
            x = w;
            y = h;
        } else if (x > 0 && y < 1) {
            w1 = x;
            h1 = x * (h / w);
        } else if (y > 0 && x < 1) {
            w1 = y * (w / h);
            h1 = y;
        } else if (x > 0 && y > 0) {
            w1 = x;
            h1 = y;
        }

        boolean resize = w1 > 0 && h1 > 0 && w1 != w && h1 != h;
        boolean argb = request.hasArgument("argb") && request.getArgument("argb").length() == 8;

        if (!resize && !argb && !grayscale)
            return;

        // Produce a unique encapsulated id based on this image processing request
        String encapId = SecureFunc.md5(context.filename() + w1 + h1 + request.getArgument("argb") + grayscale);
        File tmp = context.site() == null ? AppConfig.get().getDirectoryCache()
                : context.site().directoryTemp();
        File file = new File(tmp, encapId + "_" + new File(context.filename()).getName());

        if (cacheEnabled && file.exists()) {
            event.context().resetAndWrite(FileUtils.readFileToByteArray(file));
            return;
        }

        Image image = resize ? img.getScaledInstance(Math.round(w1), Math.round(h1),
                AppConfig.get().getBoolean("advanced.processors.useFastGraphics", true) ? Image.SCALE_FAST
                        : Image.SCALE_SMOOTH)
                : img;

        // TODO Report malformed parameters to user

        if (argb) {
            FilteredImageSource filteredSrc = new FilteredImageSource(image.getSource(),
                    new RGBColorFilter((int) Long.parseLong(request.getArgument("argb"), 16)));
            image = Toolkit.getDefaultToolkit().createImage(filteredSrc);
        }

        BufferedImage rtn = new BufferedImage(Math.round(w1), Math.round(h1), img.getType());
        Graphics2D graphics = rtn.createGraphics();
        graphics.drawImage(image, 0, 0, null);
        graphics.dispose();

        if (grayscale) {
            ColorConvertOp op = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null);
            op.filter(rtn, rtn);
        }

        if (resize)
            Log.get().info(EnumColor.GRAY + "Resized image from " + Math.round(w) + "px by " + Math.round(h)
                    + "px to " + Math.round(w1) + "px by " + Math.round(h1) + "px");

        if (rtn != null) {
            ByteArrayOutputStream bs = new ByteArrayOutputStream();

            if (context.contentType() != null
                    && writerFormats.contains(context.contentType().split("/")[1].toLowerCase()))
                ImageIO.write(rtn, context.contentType().split("/")[1].toLowerCase(), bs);
            else
                ImageIO.write(rtn, "png", bs);

            if (cacheEnabled && !file.exists())
                FileUtils.writeByteArrayToFile(file, bs.toByteArray());

            event.context().resetAndWrite(bs.toByteArray());
        }
    } catch (Throwable e) {
        e.printStackTrace();
    }

    return;
}

From source file:de.freese.base.swing.mac_os_x.MyApp.java

/**
 * @see//from  w  w w .j  av  a2 s . c om
 * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
 */
@Override
public void actionPerformed(final ActionEvent e) {
    Object source = e.getSource();

    if (source == this.quitMI) {
        quit();
    } else {
        if (source == this.optionsMI) {
            preferences();
        } else {
            if (source == this.aboutMI) {
                about();
            } else {
                if (source == this.openMI) {
                    // File:Open action shows a FileDialog for loading displayable images
                    FileDialog openDialog = new FileDialog(this);
                    openDialog.setMode(FileDialog.LOAD);
                    openDialog.setFilenameFilter(new FilenameFilter() {
                        /**
                         * @see java.io.FilenameFilter#accept(java.io.File,
                         * java.lang.String)
                         */
                        @Override
                        public boolean accept(final File dir, final String name) {
                            String[] supportedFiles = ImageIO.getReaderFormatNames();

                            for (String supportedFile : supportedFiles) {
                                if (name.endsWith(supportedFile)) {
                                    return true;
                                }
                            }

                            return false;
                        }
                    });

                    openDialog.setVisible(true);
                    String filePath = openDialog.getDirectory() + openDialog.getFile();

                    if (filePath.length() > 0) {
                        loadImageFile(filePath);
                    }
                }
            }
        }
    }
}

From source file:com.lm.lic.manager.util.GenUtil.java

public static String senseImageFormat(byte[] icon) throws Exception {
    try {/*from  ww w .j  ava  2s  .c  o  m*/
        ByteArrayInputStream bais = new ByteArrayInputStream(icon);
        // Create an image input stream on the image
        ImageInputStream iis = ImageIO.createImageInputStream(bais);
        ImageIO.getReaderFormatNames();

        // Find all image readers that recognize the image format
        Iterator<ImageReader> iter = ImageIO.getImageReaders(iis);
        if (!iter.hasNext()) {
            return null;
        }
        ImageReader reader = iter.next();
        iis.close();
        return reader.getFormatName();
    } catch (IOException e) {
    }

    return null;
}

From source file:com.occamlab.te.parsers.ImageParser.java

/**
 * Gets the supported image types in the ImageIO class (gives a
 * comma-seperated list)/*from  w  ww .  java 2s .  co  m*/
 */
public static String getSupportedImageTypes() {
    String[] readers = ImageIO.getReaderFormatNames();
    ArrayList<String> imageArray = new ArrayList<String>();
    String str = "";
    for (int i = 0; i < readers.length; i++) {
        String current = readers[i].toLowerCase();
        if (!imageArray.contains(current)) {
            imageArray.add(current);
            str += current + ",";
        }
    }
    return str.substring(0, str.lastIndexOf(","));
}