List of usage examples for javax.imageio ImageReader addIIOReadProgressListener
public void addIIOReadProgressListener(IIOReadProgressListener listener)
From source file:Main.java
static public void main(String args[]) throws Exception { FileInputStream fin = new FileInputStream("a.gif"); Iterator readers = ImageIO.getImageReadersBySuffix("GIF"); ImageReader imageReader = (ImageReader) readers.next(); ImageInputStream iis = ImageIO.createImageInputStream(fin); imageReader.setInput(iis, false);/*from w ww .ja va 2 s . c o m*/ imageReader.addIIOReadProgressListener(new IIOReadProgressListener() { public void imageComplete(ImageReader source) { System.out.println("image complete " + source); } public void imageProgress(ImageReader source, float percentageDone) { System.out.println("image progress " + source + ": " + percentageDone + "%"); } public void imageStarted(ImageReader source, int imageIndex) { System.out.println("image #" + imageIndex + " started " + source); } public void readAborted(ImageReader source) { System.out.println("read aborted " + source); } public void sequenceComplete(ImageReader source) { System.out.println("sequence complete " + source); } public void sequenceStarted(ImageReader source, int minIndex) { System.out.println("sequence started " + source + ": " + minIndex); } public void thumbnailComplete(ImageReader source) { System.out.println("thumbnail complete " + source); } public void thumbnailProgress(ImageReader source, float percentageDone) { System.out.println("thumbnail started " + source + ": " + percentageDone + "%"); } public void thumbnailStarted(ImageReader source, int imageIndex, int thumbnailIndex) { System.out.println("thumbnail progress " + source + ", " + thumbnailIndex + " of " + imageIndex); } }); BufferedImage image = imageReader.read(0); Iterator imageWriters = ImageIO.getImageWritersBySuffix("JPG"); ImageWriter imageWriter = (ImageWriter) imageWriters.next(); File file = new File("b.JPG"); ImageOutputStream ios = ImageIO.createImageOutputStream(file); imageWriter.setOutput(ios); imageWriter.write(image); }
From source file:de.cismet.cids.custom.objecteditors.wunda_blau.WebDavPicturePanel.java
/** * DOCUMENT ME!// ww w. j a v a 2s . co m * * @param fileName DOCUMENT ME! * * @return DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ private BufferedImage downloadImageFromWebDAV(final String fileName) throws Exception { final InputStream iStream = webdavHelper.getFileFromWebDAV(fileName, webdavDirectory, getConnectionContext()); try { final ImageInputStream iiStream = ImageIO.createImageInputStream(iStream); final Iterator<ImageReader> itReader = ImageIO.getImageReaders(iiStream); if (itReader.hasNext()) { final ImageReader reader = itReader.next(); final ProgressMonitor monitor = new ProgressMonitor(this, "Bild wird bertragen...", "", 0, 100); // monitor.setMillisToPopup(500); reader.addIIOReadProgressListener(new IIOReadProgressListener() { @Override public void sequenceStarted(final ImageReader source, final int minIndex) { } @Override public void sequenceComplete(final ImageReader source) { } @Override public void imageStarted(final ImageReader source, final int imageIndex) { monitor.setProgress(monitor.getMinimum()); } @Override public void imageProgress(final ImageReader source, final float percentageDone) { if (monitor.isCanceled()) { try { iiStream.close(); } catch (final IOException ex) { // NOP } } else { monitor.setProgress(Math.round(percentageDone)); } } @Override public void imageComplete(final ImageReader source) { monitor.setProgress(monitor.getMaximum()); } @Override public void thumbnailStarted(final ImageReader source, final int imageIndex, final int thumbnailIndex) { } @Override public void thumbnailProgress(final ImageReader source, final float percentageDone) { } @Override public void thumbnailComplete(final ImageReader source) { } @Override public void readAborted(final ImageReader source) { monitor.close(); } }); final ImageReadParam param = reader.getDefaultReadParam(); reader.setInput(iiStream, true, true); final BufferedImage result; try { result = reader.read(0, param); } finally { reader.dispose(); iiStream.close(); } return result; } else { return null; } } finally { IOUtils.closeQuietly(iStream); } }