Java Code Examples for javax.imageio.ImageIO#getReaderFormatNames()

The following examples show how to use javax.imageio.ImageIO#getReaderFormatNames() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DHImagePluginTemplate.java    From openstego with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method to get the list of supported file extensions for reading
 *
 * @return List of supported file extensions for reading
 * @throws OpenStegoException
 */
@Override
public List<String> getReadableFileExtensions() throws OpenStegoException {
    if (readFormats != null) {
        return readFormats;
    }

    String format = null;
    String[] formats = null;
    readFormats = new ArrayList<String>();

    formats = ImageIO.getReaderFormatNames();
    for (int i = 0; i < formats.length; i++) {
        format = formats[i].toLowerCase();
        if (format.indexOf("jpeg") >= 0 && format.indexOf("2000") >= 0) {
            format = "jp2";
        }
        if (!readFormats.contains(format)) {
            readFormats.add(format);
        }
    }

    Collections.sort(readFormats);
    return readFormats;
}
 
Example 2
Source File: WMImagePluginTemplate.java    From openstego with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method to get the list of supported file extensions for reading
 *
 * @return List of supported file extensions for reading
 * @throws OpenStegoException
 */
@Override
public List<String> getReadableFileExtensions() throws OpenStegoException {
    if (readFormats != null) {
        return readFormats;
    }

    String format = null;
    String[] formats = null;
    readFormats = new ArrayList<String>();

    formats = ImageIO.getReaderFormatNames();
    for (int i = 0; i < formats.length; i++) {
        format = formats[i].toLowerCase();
        if (format.indexOf("jpeg") >= 0 && format.indexOf("2000") >= 0) {
            format = "jp2";
        }
        if (!readFormats.contains(format)) {
            readFormats.add(format);
        }
    }

    Collections.sort(readFormats);
    return readFormats;
}
 
Example 3
Source File: DCTPluginTemplate.java    From openstego with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Method to get the list of supported file extensions for reading
 *
 * @return List of supported file extensions for reading
 * @throws OpenStegoException
 */
@Override
public List<String> getReadableFileExtensions() throws OpenStegoException {
    if (readFormats != null) {
        return readFormats;
    }

    String format = null;
    String[] formats = null;
    List<String> formatList = new ArrayList<String>();

    formats = ImageIO.getReaderFormatNames();
    for (int i = 0; i < formats.length; i++) {
        format = formats[i].toLowerCase();
        if (format.indexOf("jpeg") >= 0 && format.indexOf("2000") >= 0) {
            format = "jp2";
        }
        if (!formatList.contains(format)) {
            formatList.add(format);
        }
    }

    Collections.sort(formatList);
    readFormats = formatList;
    return readFormats;
}
 
Example 4
Source File: DeregisterAllSpiTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public DeregisterAllSpiTest() throws Exception {
    ImageReaderSpi BMPSpi = new BMPImageReaderSPI();
    IIORegistry.getDefaultInstance().registerServiceProvider(BMPSpi);

    System.out.println("Reader Format Names available in the registry");
    String formatNames[] = ImageIO.getReaderFormatNames();
    if( formatNames == null || formatNames.length <= 0) {
        throw new RuntimeException("No registered ImageReaders!");
    }
    for (int x=0; x < formatNames.length; x++) {
        System.out.println("format "+formatNames[x]);
    }

    IIORegistry.getDefaultInstance().deregisterAll();

    System.out.println("\nReader Format Names after deregistering all SPIs");
    formatNames = ImageIO.getReaderFormatNames();
    if(formatNames.length == 0) {
        System.out.println("No readers available\n");
    } else {
        throw new RuntimeException("Some providers was not deregistered!");
    }

    IIORegistry.getDefaultInstance().registerServiceProvider(BMPSpi);
    System.out.println("Reader Format Names after re-register of BMP Plugin");
    formatNames = ImageIO.getReaderFormatNames();
    if(formatNames.length == 0) {
        throw new RuntimeException("Unable to register new SPI after deregisterAll()!");
    }
}
 
Example 5
Source File: ImageParser.java    From teamengine with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the supported image types in the ImageIO class (gives a
 * comma-seperated list)
 */
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(","));
}
 
Example 6
Source File: NavigableImagePanel.java    From PyramidShader with GNU General Public License v3.0 5 votes vote down vote up
private static String[] getImageFormatExtensions() {
    String[] names = ImageIO.getReaderFormatNames();
    for (int i = 0; i < names.length; i++) {
        names[i] = names[i].toLowerCase();
    }
    Arrays.sort(names);
    return names;
}
 
Example 7
Source File: GetReaderWriterInfo.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void testGetReaderFormatNames() {
    String[] names = ImageIO.getReaderFormatNames();
    for (String n : names) {
        Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName(n);
        if (!it.hasNext()) {
            throw new RuntimeException("getReaderFormatNames returned " +
                                       "an unknown name: " + n);
        }
    }
}
 
Example 8
Source File: IIOPluginTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    SecurityManager sm = System.getSecurityManager();
    System.out.println("Sm is " + sm);

    String formatNames[] = ImageIO.getReaderFormatNames();
    String readerMimeTypes[] = ImageIO.getReaderMIMETypes();

    if (!isPresent(dummyformatNames, formatNames) ||
        !isPresent(dummymimeType, readerMimeTypes)) {
        throw new RuntimeException("No test plugin available!");
    }
}
 
Example 9
Source File: CacheWriter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private String[] findImageFiles (File root) {
    String[] formats = ImageIO.getReaderFormatNames();
    Set set = new HashSet();
    findImageFiles (root, set);
    String[] result = new String[set.size()];
    result = (String[]) set.toArray(result);
    return result;
}
 
Example 10
Source File: NavigableImagePanel.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
private static String[] getImageFormatExtensions() {
	String[] names = ImageIO.getReaderFormatNames();
	for(int i = 0; i < names.length; i++) {
		names[i] = names[i].toLowerCase();
	}
	Arrays.sort(names);
	return names;
}
 
Example 11
Source File: NavigableImagePanel.java    From Ngram-Graphs with Apache License 2.0 5 votes vote down vote up
private static String[] getImageFormatExtensions() {
	String[] names = ImageIO.getReaderFormatNames();
	for(int i = 0; i < names.length; i++) {
		names[i] = names[i].toLowerCase();
	}
	Arrays.sort(names);
	return names;
}
 
Example 12
Source File: ImageUtil.java    From javautils with Apache License 2.0 5 votes vote down vote up
/**
 * 读取图片,获取ImageReader对象
 * @param fileName
 * @return
 */
public static ImageReader getImageReader(String fileName){
    if(fileName != null){
        String suffix = "";
        for(String str : ImageIO.getReaderFormatNames()){
            if(fileName.lastIndexOf(Constants.POINT_STR + str) > 0){
                suffix = str;
            }
        }

        if(!"".equals(suffix)){
            try {
                // 将FileInputStream 转换为ImageInputStream
                ImageInputStream iis = ImageIO.createImageInputStream(new FileInputStream(fileName));
                // 根据图片类型获取该种类型的ImageReader
                Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName(suffix);
                ImageReader reader = readers.next();
                reader.setInput(iis, true);
                return reader;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }

    return null;
}
 
Example 13
Source File: GetReaderWriterInfo.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void testGetReaderFormatNames() {
    String[] names = ImageIO.getReaderFormatNames();
    for (String n : names) {
        Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName(n);
        if (!it.hasNext()) {
            throw new RuntimeException("getReaderFormatNames returned " +
                                       "an unknown name: " + n);
        }
    }
}
 
Example 14
Source File: IIOPluginTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    SecurityManager sm = System.getSecurityManager();
    System.out.println("Sm is " + sm);

    String formatNames[] = ImageIO.getReaderFormatNames();
    String readerMimeTypes[] = ImageIO.getReaderMIMETypes();

    if (!isPresent(dummyformatNames, formatNames) ||
        !isPresent(dummymimeType, readerMimeTypes)) {
        throw new RuntimeException("No test plugin available!");
    }
}
 
Example 15
Source File: DeregisterAllSpiTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public DeregisterAllSpiTest() throws Exception {
    ImageReaderSpi BMPSpi = new BMPImageReaderSPI();
    IIORegistry.getDefaultInstance().registerServiceProvider(BMPSpi);

    System.out.println("Reader Format Names available in the registry");
    String formatNames[] = ImageIO.getReaderFormatNames();
    if( formatNames == null || formatNames.length <= 0) {
        throw new RuntimeException("No registered ImageReaders!");
    }
    for (int x=0; x < formatNames.length; x++) {
        System.out.println("format "+formatNames[x]);
    }

    IIORegistry.getDefaultInstance().deregisterAll();

    System.out.println("\nReader Format Names after deregistering all SPIs");
    formatNames = ImageIO.getReaderFormatNames();
    if(formatNames.length == 0) {
        System.out.println("No readers available\n");
    } else {
        throw new RuntimeException("Some providers was not deregistered!");
    }

    IIORegistry.getDefaultInstance().registerServiceProvider(BMPSpi);
    System.out.println("Reader Format Names after re-register of BMP Plugin");
    formatNames = ImageIO.getReaderFormatNames();
    if(formatNames.length == 0) {
        throw new RuntimeException("Unable to register new SPI after deregisterAll()!");
    }
}
 
Example 16
Source File: CacheWriter.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public FormatFilenameFilter () {
    formats = ImageIO.getReaderFormatNames();
    String[] s = new String[formats.length + 2];
    System.arraycopy (formats, 0, s, 2, formats.length);
    s[0] = "GIF";
    s[1] = "gif";
    formats = s;
}
 
Example 17
Source File: ImageLoadJaiTest.java    From java-image-processing-survival-guide with Apache License 2.0 4 votes vote down vote up
/**
 * List available image formats.
 * see http://examples.javacodegeeks.com/desktop-java/imageio/list-read-write-supported-image-formats/
 */
@Test
public void testListSupportedImageFormats() throws Exception {

    Set<String> set = new HashSet<String>();

    // Get list of all informal format names understood by the current set of registered readers
    String[] formatNames = ImageIO.getReaderFormatNames();

    for (int i = 0; i < formatNames.length; i++) {
        set.add(formatNames[i].toLowerCase());
    }
    System.out.println("Supported read formats: " + set);

    set.clear();

    // Get list of all informal format names understood by the current set of registered writers
    formatNames = ImageIO.getWriterFormatNames();

    for (int i = 0; i < formatNames.length; i++) {
        set.add(formatNames[i].toLowerCase());
    }
    System.out.println("Supported write formats: " + set);

    set.clear();

    // Get list of all MIME types understood by the current set of registered readers
    formatNames = ImageIO.getReaderMIMETypes();

    for (int i = 0; i < formatNames.length; i++) {
        set.add(formatNames[i].toLowerCase());
    }
    System.out.println("Supported read MIME types: " + set);

    set.clear();

    // Get list of all MIME types understood by the current set of registered writers
    formatNames = ImageIO.getWriterMIMETypes();

    for (int i = 0; i < formatNames.length; i++) {
        set.add(formatNames[i].toLowerCase());
    }
    System.out.println("Supported write MIME types: " + set);
}