Java Code Examples for javax.imageio.ImageIO.getImageWriters()

The following are Jave code examples for showing how to use getImageWriters() of the javax.imageio.ImageIO class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: CanEncodeShort.java   View Source Code Vote up 6 votes
public static void main(String[] args) {
    for (int i = 0; i < types.length; i++) {
        BufferedImage img = new BufferedImage(32, 32, types[i]);

        ImageTypeSpecifier spec =
            ImageTypeSpecifier.createFromRenderedImage(img);

        Iterator writers = ImageIO.getImageWriters(spec, "png");

        if (!writers.hasNext()) {
            throw new RuntimeException("Test failed: " +
                                       "no PNG writer found for type " +
                                       typeNames[i]);
        }
    }
}
 
Example 2
Project: openjdk-jdk10   File: CanEncodeIndexed.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    BufferedImage img = new BufferedImage(32, 32,
                                          BufferedImage.TYPE_BYTE_INDEXED);

    ImageTypeSpecifier spec =
        ImageTypeSpecifier.createFromRenderedImage(img);

    Iterator writers = ImageIO.getImageWriters(spec, "jpeg");

    if (!writers.hasNext()) {
        throw new RuntimeException("Test failed: " +
                                   "no JPEG writer found for " +
                                   "image with IndexColorModel");
    }
}
 
Example 3
Project: openjdk-jdk10   File: BitDepth.java   View Source Code Vote up 5 votes
private File testWriteRGB(String format, int type) throws IOException {

        BufferedImage bi = new BufferedImage(width, height, type);
        Graphics2D g = bi.createGraphics();

        Color white = new Color(255, 255, 255);
        Color red = new Color(255, 0, 0);
        Color green = new Color(0, 255, 0);
        Color blue = new Color(0, 0, 255);

        g.setColor(white);
        g.fillRect(0, 0, width, height);
        g.setColor(red);
        g.fillRect(10, 10, 20, 20);
        g.setColor(green);
        g.fillRect(30, 30, 20, 20);
        g.setColor(blue);
        g.fillRect(50, 50, 20, 20);

        ImageTypeSpecifier spec = new ImageTypeSpecifier(bi);
        Iterator<ImageWriter> writers = ImageIO.getImageWriters(spec, format);
        File file = new File("BitDepth_" + biTypeNames[type] + "." + format);
        if (!writers.hasNext()) {
            System.out.println("\tNo writers available for type " + biTypeNames[type]
                               + " BufferedImage!");
        } else {
            ImageWriter writer = writers.next();
            try (ImageOutputStream out = ImageIO.createImageOutputStream(file)) {
                writer.setOutput(out);
                writer.write(bi);
            } catch (Exception e) {
                System.out.println("\tCan't write a type " +  biTypeNames[type]
                           + " BufferedImage!");
                return null;
            }
        }

        return file;
    }