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


Java ImageIO.getImageWritersBySuffix方法代碼示例

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


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

示例1: save

import javax.imageio.ImageIO; //導入方法依賴的package包/類
void save(File file) throws IOException {
    ImageWriter iw = null;
    String name = file.getName();
    int i = name.lastIndexOf('.');
    if (i >= 0) {
        String extension = name.substring(i + 1);
        Iterator<ImageWriter> imageWritersBySuffix = ImageIO.getImageWritersBySuffix(extension);
        if (imageWritersBySuffix.hasNext()) {
            iw = imageWritersBySuffix.next();
        }
    }
    if (iw != null) {
        file.delete();
        ImageOutputStream ios = ImageIO.createImageOutputStream(file);
        iw.setOutput(ios);
        try {
            iw.write((BufferedImage) image);
        } finally {
            iw.dispose();
            ios.flush();
            ios.close();
        }
    } else {
        ImageIO.write((BufferedImage) image, "PNG", file);
    }
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:27,代碼來源:ScreenshotComponent.java

示例2: testGetWriterFileSuffixes

import javax.imageio.ImageIO; //導入方法依賴的package包/類
private static void testGetWriterFileSuffixes() {
    String[] suffixes = ImageIO.getWriterFileSuffixes();
    for (String s : suffixes) {
        Iterator<ImageWriter> it = ImageIO.getImageWritersBySuffix(s);
        if (!it.hasNext()) {
            throw new RuntimeException("getWriterFileSuffixes returned " +
                                       "an unknown suffix: " + s);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:11,代碼來源:GetReaderWriterInfo.java

示例3: main

import javax.imageio.ImageIO; //導入方法依賴的package包/類
public static void main(String[] args) {
    Locale.setDefault(Locale.US);

    final BufferedImage image
        = new BufferedImage(512, 512, BufferedImage.TYPE_INT_ARGB);

    final Graphics2D g2d = image.createGraphics();
    try {
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                             RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING,
                             RenderingHints.VALUE_RENDER_QUALITY);
        g2d.scale(2.0, 2.0);

        g2d.setColor(Color.red);
        g2d.draw(new Rectangle2D.Float(10, 10, 100, 100));
        g2d.setColor(Color.blue);
        g2d.fill(new Rectangle2D.Float(12, 12, 98, 98));
        g2d.setColor(Color.green);
        g2d.setFont(new Font(Font.SERIF, Font.BOLD, 14));

        for (int i = 0; i < 15; i++) {
            g2d.drawString("Testing Compression ...", 20, 20 + i * 16);
        }

        final String[] fileSuffixes = ImageIO.getWriterFileSuffixes();

        final Set<String> testedWriterClasses = new HashSet<String>();

        for (String suffix : fileSuffixes) {

            if (!IGNORE_FILE_SUFFIXES.contains(suffix)) {
                final Iterator<ImageWriter> itWriters
                    = ImageIO.getImageWritersBySuffix(suffix);

                final ImageWriter writer;
                final ImageWriteParam writerParams;

                if (itWriters.hasNext()) {
                    writer = itWriters.next();

                    if (testedWriterClasses.add(writer.getClass().getName())) {
                        writerParams = writer.getDefaultWriteParam();

                        if (writerParams.canWriteCompressed()) {
                            testCompression(image, writer, writerParams, suffix);
                        }
                    }
                } else {
                    throw new RuntimeException("Unable to get writer !");
                }
            }
        }
    } catch (IOException ioe) {
        throw new RuntimeException("IO failure", ioe);
    }
    finally {
        g2d.dispose();
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:61,代碼來源:ImageWriterCompressionTest.java


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