當前位置: 首頁>>代碼示例>>Java>>正文


Java ImageIO.getImageWriters方法代碼示例

本文整理匯總了Java中javax.imageio.ImageIO.getImageWriters方法的典型用法代碼示例。如果您正苦於以下問題:Java ImageIO.getImageWriters方法的具體用法?Java ImageIO.getImageWriters怎麽用?Java ImageIO.getImageWriters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.imageio.ImageIO的用法示例。


在下文中一共展示了ImageIO.getImageWriters方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import javax.imageio.ImageIO; //導入方法依賴的package包/類
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]);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:CanEncodeShort.java

示例2: main

import javax.imageio.ImageIO; //導入方法依賴的package包/類
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");
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:16,代碼來源:CanEncodeIndexed.java

示例3: testWriteRGB

import javax.imageio.ImageIO; //導入方法依賴的package包/類
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;
    }
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:40,代碼來源:BitDepth.java


注:本文中的javax.imageio.ImageIO.getImageWriters方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。