String[] formats = ImageIO.getReaderFormatNames(); for( int i = 0; i < formats.length; i++ )
private static String getFormatsString() { String[] formats = ImageIO.getReaderFormatNames(); StringBuilder buf = new StringBuilder(); for (int i = 0; i < formats.length; i++) { String format = formats[i]; if (i > 0) { buf.append(", "); } buf.append(format); } return buf.toString(); }
/** * Returns a sorted array of format names, that can be read by ImageIO. * The names are all upper-case, and contains no duplicates. * * @return a normalized array of {@code String}s. * @see javax.imageio.ImageIO#getReaderFormatNames() */ public static String[] getNormalizedReaderFormatNames() { return normalizeNames(ImageIO.getReaderFormatNames()); }
private static String getImageFormats() { StringBuilder retval = new StringBuilder(); String[] formats = ImageIO.getReaderFormatNames(); for( int i = 0; i < formats.length; i++ ) { if (formats[i].equalsIgnoreCase(formats[i])) { retval.append( formats[i] ); if( i + 1 < formats.length ) { retval.append( ", " ); } } } return retval.toString(); }
System.err.println("Usage: IndexImage [--help|-h] [--speedtest|-s <integer>] [--bgcolor|-b <color>] [--colors|-c <integer> | --grayscale|g | --monochrome|-m | --palette|-p <file>] [--dither|-d (default|diffusion|none)] [--quality|-q (default|high|low)] [--transparency|-t] [--outputformat|-f (gif|jpeg|png|wbmp|...)] [--overwrite|-w] <input> [<output>]"); System.err.print("Input format names: "); String[] readers = ImageIO.getReaderFormatNames();
public static void printImageFormatNames() { System.out.println("Informa Names:"); for (String s : ImageIO.getReaderFormatNames()) { System.out.println(s); } }
private static String[] getFormatNamesList() { final List<String> names = new ArrayList<>(40); names.add("ImageIO"); names.addAll(Arrays.asList(ImageIO.getReaderFormatNames())); names.remove("geotiff"); return names.toArray(new String[names.size()]); }
private static String getImageFormats() { StringBuilder retval = new StringBuilder(); String[] formats = ImageIO.getReaderFormatNames(); for( int i = 0; i < formats.length; i++ ) { if (formats[i].equalsIgnoreCase(formats[i])) { retval.append( formats[i] ); if( i + 1 < formats.length ) { retval.append( ", " ); } } } return retval.toString(); }
/** * Returns a sorted array of format names, that can be read by ImageIO. * The names are all upper-case, and contains no duplicates. * * @return a normalized array of {@code String}s. * @see javax.imageio.ImageIO#getReaderFormatNames() */ public static String[] getNormalizedReaderFormatNames() { return normalizeNames(ImageIO.getReaderFormatNames()); }
public static void main(String[] pArgs) throws IOException { BufferedImage image = ImageIO.read(new File(pArgs[0])); if (image == null) { System.err.println("Supported formats: " + Arrays.toString(ImageIO.getReaderFormatNames())); System.exit(1); } showIt(image, pArgs[0]); }
/** * 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(",")); }
/** * 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(",")); }
public static void registerLoader() { if (supportedFormats == null) { final List<String> formats = Lists.newArrayList(); for (String format : ImageIO.getReaderFormatNames()) { format = "." + format.toUpperCase(); if (!formats.contains(format)) { formats.add(format); } } supportedFormats = formats.toArray(new String[formats.size()]); } ImageLoaderUtil.registerHandler(new AWTImageLoader(), supportedFormats); }
public static void registerLoader() { if (supportedFormats == null) { final List<String> formats = Lists.newArrayList(); for (String format : ImageIO.getReaderFormatNames()) { format = "." + format.toUpperCase(); if (!formats.contains(format)) { formats.add(format); } } supportedFormats = formats.toArray(new String[formats.size()]); } ImageLoaderUtil.registerHandler(new AWTImageLoader(), supportedFormats); }
public static boolean thumbnailImage(File imgFile, int w, int h,String path){ try { // ImageIO 支持的图片类型 : [BMP, bmp, jpg, JPG, wbmp, jpeg, png, PNG, JPEG, WBMP, GIF, gif] String types = Arrays.toString(ImageIO.getReaderFormatNames()); String suffix = null; // 获取图片后缀 if(imgFile.getName().indexOf(".") > -1) { suffix = imgFile.getName().substring(imgFile.getName().lastIndexOf(".") + 1); }// 类型和图片后缀全部小写,然后判断后缀是否合法 if(suffix == null || types.toLowerCase().indexOf(suffix.toLowerCase()) < 0){ return false; } Image img = ImageIO.read(imgFile); //BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB); Graphics g = bi.getGraphics(); g.drawImage(img, 0, 0, w, h, Color.LIGHT_GRAY, null); g.dispose(); // 将图片保存在原目录并加上前缀 ImageIO.write(bi, getFormatName(imgFile), new File(path)); return true; } catch (IOException e) { e.printStackTrace(); return false; } } /**
@Override protected BufferedImage refreshBufferedImage() { try { return ImageIO.read(new ByteArrayInputStream(frameBuffer, 0, frameLength)); } catch (IOException e) { System.err.println("It seems your JVM is unable to decode this image."); // print supported image types and mime types System.err.println("Supported image types:"); String supportedTypes[] = ImageIO.getReaderFormatNames(); for (String name : supportedTypes) System.err.println(name); System.err.println("Supported MIME types:"); String supportedMimeTypes[] = ImageIO.getReaderMIMETypes(); for (String name : supportedMimeTypes) System.err.println(name); e.printStackTrace(); throw new UnsupportedMethod("Unable to decode the image", e); } }
String[] formatNames = ImageIO.getReaderFormatNames();
for (String formatName : ImageIO.getReaderFormatNames())
@Override public Object execute() throws IOException { // Refresh registry. IIORegistry registry = IIORegistry.getDefaultInstance(); registry.registerServiceProviders(ServiceRegistry.lookupProviders(ImageReaderSpi.class)); registry.registerServiceProviders(ServiceRegistry.lookupProviders(ImageWriterSpi.class)); System.out.println("Available image readers:"); for (String reader : ImageIO.getReaderFormatNames()) { System.out.println("\t" + reader); Iterator<ImageReader> imageReaders = ImageIO.getImageReadersByFormatName(reader); while (imageReaders.hasNext()) { System.out.println("\t\t" + imageReaders.next()); } } System.out.println(); System.out.println("Available image writers:"); for (String writer : ImageIO.getWriterFormatNames()) { System.out.println("\t" + writer); Iterator<ImageWriter> imageWriters = ImageIO.getImageWritersByFormatName(writer); while (imageWriters.hasNext()) { System.out.println("\t\t" + imageWriters.next()); } } return null; }
@Test public void testname() throws Exception { System.out.println(Arrays.asList(ImageIO.getReaderMIMETypes())); System.out.println(Arrays.asList(ImageIO.getWriterFormatNames())); System.out.println(Arrays.asList(ImageIO.getReaderFormatNames())); URL pngFile = getClass().getResource("/test.png"); BufferedImage img = ImageIO.read(pngFile); for (String type : ImageIO.getWriterFormatNames()) { if (type.equalsIgnoreCase("jpg") || type.equalsIgnoreCase("jpeg")) { // Avoid issue #6 on OpenJDK8/Debian continue; } File f = File.createTempFile("imageio-test", "." + type); ImageIO.write(img, type, f); System.out.println(f); ImageIO.read(f); } }