Java examples for 2D Graphics:BufferedImage
get Java Image Reader
//package com.java2s; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.imageio.ImageIO; import javax.imageio.ImageReader; public class Main { public static ImageReader getJavaImageReader(boolean preferBetter) { ImageReader imwriter = null; // com.sun.media.imageioimpl.plugins.png.CLibPNGImageWriter (better) // com.sun.imageio.plugins.png.PNGImageWriter List<ImageReader> list = new ArrayList<ImageReader>(); for (Iterator<ImageReader> iter = ImageIO .getImageReadersByFormatName("PNG"); iter.hasNext();) { list.add(iter.next());//from w w w . j ava2 s . co m } for (ImageReader iw : list) { String cname = iw.getOriginatingProvider().getPluginClassName(); if (cname.startsWith("com.sun.media.imageio") && preferBetter) { imwriter = iw; break; } if (cname.startsWith("com.sun.imageio.plugins.png.") && !preferBetter) { imwriter = iw; break; } } if (imwriter == null) imwriter = list.get(0); return imwriter; } }