📄 imageio.java
字号:
} private static Iterator getWritersByFilter(Class type, ServiceRegistry.Filter filter, Object writerExtension) { try { Iterator it = getRegistry().getServiceProviders(type, filter, true); return new ImageWriterIterator(it, writerExtension); } catch (IllegalArgumentException e) { return Collections.EMPTY_SET.iterator(); } } public static File getCacheDirectory() { return cacheDirectory; } public static Iterator getImageReadersByFormatName(String formatName) { if (formatName == null) throw new IllegalArgumentException("formatName may not be null"); return getReadersByFilter(ImageReaderSpi.class, new ReaderFormatFilter(formatName), formatName); } public static Iterator getImageReadersByMIMEType(String MIMEType) { if (MIMEType == null) throw new IllegalArgumentException("MIMEType may not be null"); return getReadersByFilter(ImageReaderSpi.class, new ReaderMIMETypeFilter(MIMEType), MIMEType); } public static Iterator getImageReadersBySuffix(String fileSuffix) { if (fileSuffix == null) throw new IllegalArgumentException("formatName may not be null"); return getReadersByFilter(ImageReaderSpi.class, new ReaderSuffixFilter(fileSuffix), fileSuffix); } public static Iterator getImageWritersByFormatName(String formatName) { if (formatName == null) throw new IllegalArgumentException("formatName may not be null"); return getWritersByFilter(ImageWriterSpi.class, new WriterFormatFilter(formatName), formatName); } public static Iterator getImageWritersByMIMEType(String MIMEType) { if (MIMEType == null) throw new IllegalArgumentException("MIMEType may not be null"); return getWritersByFilter(ImageWriterSpi.class, new WriterMIMETypeFilter(MIMEType), MIMEType); } public static Iterator getImageWritersBySuffix(String fileSuffix) { if (fileSuffix == null) throw new IllegalArgumentException("fileSuffix may not be null"); return getWritersByFilter(ImageWriterSpi.class, new WriterSuffixFilter(fileSuffix), fileSuffix); } public static String[] getReaderFormatNames() { try { Iterator it = getRegistry().getServiceProviders(ImageReaderSpi.class, true); ArrayList result = new ArrayList(); while (it.hasNext()) { ImageReaderSpi spi = (ImageReaderSpi) it.next(); String[] names = spi.getFormatNames(); for (int i = names.length - 1; i >= 0; --i) result.add(names[i]); } return (String[]) result.toArray(new String[result.size()]); } catch (IllegalArgumentException e) { return new String[0]; } } public static String[] getReaderMIMETypes() { try { Iterator it = getRegistry().getServiceProviders(ImageReaderSpi.class, true); ArrayList result = new ArrayList(); while (it.hasNext()) { ImageReaderSpi spi = (ImageReaderSpi) it.next(); String[] names = spi.getMIMETypes(); for (int i = names.length - 1; i >= 0; --i) result.add(names[i]); } return (String[]) result.toArray(new String[result.size()]); } catch (IllegalArgumentException e) { return new String[0]; } } private static IIORegistry getRegistry() { return IIORegistry.getDefaultInstance(); } public static boolean getUseCache() { return useCache; } public static String[] getWriterFormatNames() { try { Iterator it = getRegistry().getServiceProviders(ImageWriterSpi.class, true); ArrayList result = new ArrayList(); while (it.hasNext()) { ImageWriterSpi spi = (ImageWriterSpi) it.next(); String[] names = spi.getFormatNames(); for (int i = names.length - 1; i >= 0; --i) result.add(names[i]); } return (String[]) result.toArray(new String[result.size()]); } catch (IllegalArgumentException e) { return new String[0]; } } public static String[] getWriterMIMETypes() { try { Iterator it = getRegistry().getServiceProviders(ImageWriterSpi.class, true); ArrayList result = new ArrayList(); while (it.hasNext()) { ImageWriterSpi spi = (ImageWriterSpi) it.next(); String[] names = spi.getMIMETypes(); for (int i = names.length - 1; i >= 0; --i) result.add(names[i]); } return (String[]) result.toArray(new String[result.size()]); } catch (IllegalArgumentException e) { return new String[0]; } } /** * Rescans the application classpath for ImageIO service providers * and registers them. */ public static void scanForPlugins() { IIORegistry.getDefaultInstance().registerApplicationClasspathSpis(); } public static void setCacheDirectory(File cacheDirectory) { if (cacheDirectory != null) { if (!cacheDirectory.isDirectory()) throw new IllegalArgumentException("cacheDirectory must be a directory"); cacheDirectory.canWrite(); } ImageIO.cacheDirectory = cacheDirectory; } public static void setUseCache(boolean useCache) { ImageIO.useCache = useCache; } /* * "Standard" simplified entry points. */ public static boolean write(RenderedImage im, String formatName, File output) throws IOException { return write(im, formatName, new FileOutputStream(output)); } public static boolean write(RenderedImage im, String formatName, OutputStream output) throws IOException { return write(im, formatName, new MemoryCacheImageOutputStream(output)); } public static boolean write(RenderedImage im, String formatName, ImageOutputStream output) throws IOException { Iterator writers = getImageWritersByFormatName(formatName); IIOImage img = new IIOImage(im, null, null); while (writers.hasNext()) { ImageWriter w = (ImageWriter) writers.next(); try { w.setOutput(output); } catch (IllegalArgumentException e) { continue; } w.write(null, img, null); output.close(); return true; } return false; } public static BufferedImage read(ImageInputStream stream) throws IOException { Iterator providers = getRegistry().getServiceProviders(ImageReaderSpi.class, true); while (providers.hasNext()) { ImageReaderSpi spi = (ImageReaderSpi) providers.next(); if (spi.canDecodeInput(stream)) { ImageReader reader = spi.createReaderInstance(); reader.setInput(stream); return reader.read(0, null); } } return null; } public static BufferedImage read(URL input) throws IOException { return read(input.openStream()); } public static BufferedImage read(InputStream input) throws IOException { return read(new MemoryCacheImageInputStream(input)); } public static BufferedImage read(File input) throws IOException { return read(new FileInputStream(input)); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -