Java Code Examples for javax.imageio.ImageWriteParam#setProgressiveMode()
The following examples show how to use
javax.imageio.ImageWriteParam#setProgressiveMode() .
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: OpaquePNGToGIFTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public void createAnimatedImage(BufferedImage bi, IIOMetadata metadata, ImageWriter writer, File outputFile) { try { fos = new FileOutputStream(outputFile); ImageOutputStream ios = ImageIO.createImageOutputStream(fos); System.out.println(ios); writer.setOutput(ios); ImageWriteParam param = writer.getDefaultWriteParam(); IIOMetadata streamData = writer.getDefaultStreamMetadata(param); writer.prepareWriteSequence(streamData); ImageTypeSpecifier specify = new ImageTypeSpecifier(bi); IIOMetadata imgData = writer.convertImageMetadata( (IIOMetadata) metadata, specify, param); GIFImageMetadata gifData = setAnimationProperties(imgData); IIOImage iim = new IIOImage(bi, null, gifData); param.setProgressiveMode(param.MODE_DISABLED); writer.writeToSequence(iim, param); writer.endWriteSequence(); ios.close(); } catch (Exception e) { e.printStackTrace(); } }
Example 2
Source File: GifWriter.java From scrimage with Apache License 2.0 | 6 votes |
@Override public void write(AwtImage image, ImageMetadata metadata, OutputStream out) throws IOException { javax.imageio.ImageWriter writer = ImageIO.getImageWritersByFormatName("gif").next(); ImageWriteParam params = writer.getDefaultWriteParam(); if (progressive) { params.setProgressiveMode(ImageWriteParam.MODE_DEFAULT); } else { params.setProgressiveMode(ImageWriteParam.MODE_DISABLED); } try (MemoryCacheImageOutputStream output = new MemoryCacheImageOutputStream(out)) { writer.setOutput(output); writer.write(null, new IIOImage(image.awt(), null, null), params); writer.dispose(); } // IOUtils.closeQuietly(out); }
Example 3
Source File: ImageWriteParamMisc.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private static void test4441315() { ImageWriteParam iwp = new ImageWriteParam4441315(); try { iwp.setProgressiveMode(ImageWriteParam.MODE_EXPLICIT); throw new RuntimeException("Failed to get IAE!"); } catch (IllegalArgumentException e) { } }
Example 4
Source File: WriteProgressive.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws IOException { Iterator witer = ImageIO.getImageWritersByFormatName("png"); ImageWriter w = (ImageWriter)witer.next(); File f = File.createTempFile("WriteProgressive", ".png"); ImageOutputStream ios = ImageIO.createImageOutputStream(f); w.setOutput(ios); BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR); Graphics2D g = bi.createGraphics(); Random r = new Random(10); for (int i = 0; i < 10000; i++) { Color c = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)); g.setColor(c); g.fillRect(r.nextInt(100), r.nextInt(100), 1, 1); } IIOImage iioimage = new IIOImage(bi, null, null); ImageWriteParam param = w.getDefaultWriteParam(); param.setProgressiveMode(ImageWriteParam.MODE_DEFAULT); try { w.write(null, iioimage, param); } catch (NullPointerException npe) { throw new RuntimeException("Got NPE during write!"); } ios.close(); BufferedImage bi2 = ImageIO.read(f); f.delete(); ImageCompare.compare(bi, bi2); }
Example 5
Source File: ImageWriteParamMisc.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
private static void test4441315() { ImageWriteParam iwp = new ImageWriteParam4441315(); try { iwp.setProgressiveMode(ImageWriteParam.MODE_EXPLICIT); throw new RuntimeException("Failed to get IAE!"); } catch (IllegalArgumentException e) { } }
Example 6
Source File: WriteProgressive.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws IOException { Iterator witer = ImageIO.getImageWritersByFormatName("png"); ImageWriter w = (ImageWriter)witer.next(); File f = File.createTempFile("WriteProgressive", ".png"); ImageOutputStream ios = ImageIO.createImageOutputStream(f); w.setOutput(ios); BufferedImage bi = new BufferedImage(100, 100, BufferedImage.TYPE_3BYTE_BGR); Graphics2D g = bi.createGraphics(); Random r = new Random(10); for (int i = 0; i < 10000; i++) { Color c = new Color(r.nextInt(256), r.nextInt(256), r.nextInt(256)); g.setColor(c); g.fillRect(r.nextInt(100), r.nextInt(100), 1, 1); } IIOImage iioimage = new IIOImage(bi, null, null); ImageWriteParam param = w.getDefaultWriteParam(); param.setProgressiveMode(ImageWriteParam.MODE_DEFAULT); try { w.write(null, iioimage, param); } catch (NullPointerException npe) { throw new RuntimeException("Got NPE during write!"); } ios.close(); BufferedImage bi2 = ImageIO.read(f); f.delete(); ImageCompare.compare(bi, bi2); }
Example 7
Source File: JpegOutput.java From Pixelitor with GNU General Public License v3.0 | 5 votes |
private static void writeJPGtoStream(BufferedImage image, ImageInputStream ios, JpegInfo config, ProgressTracker tracker) throws IOException { Iterator<ImageWriter> jpgWriters = ImageIO.getImageWritersByFormatName("jpg"); if (!jpgWriters.hasNext()) { throw new IllegalStateException("No JPG writers found"); } ImageWriter writer = jpgWriters.next(); ImageWriteParam imageWriteParam = writer.getDefaultWriteParam(); if (config.isProgressive()) { imageWriteParam.setProgressiveMode(MODE_DEFAULT); } else { imageWriteParam.setProgressiveMode(MODE_DISABLED); } imageWriteParam.setCompressionMode(MODE_EXPLICIT); imageWriteParam.setCompressionQuality(config.getQuality()); IIOImage iioImage = new IIOImage(image, null, null); writer.setOutput(ios); if (tracker != null) { writer.addIIOWriteProgressListener(new TrackerWriteProgressListener(tracker)); } writer.write(null, iioImage, imageWriteParam); ios.flush(); ios.close(); }
Example 8
Source File: JpegWriter.java From scrimage with Apache License 2.0 | 5 votes |
@Override public void write(AwtImage image, ImageMetadata metadata, OutputStream out) throws IOException { javax.imageio.ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next(); ImageWriteParam params = writer.getDefaultWriteParam(); if (compression < 100) { params.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); params.setCompressionQuality(compression / 100f); } if (progressive) { params.setProgressiveMode(ImageWriteParam.MODE_DEFAULT); } else { params.setProgressiveMode(ImageWriteParam.MODE_DISABLED); } // in openjdk, awt cannot write out jpegs that have a transparency bit, even if that is set to 255. // see http://stackoverflow.com/questions/464825/converting-transparent-gif-png-to-jpeg-using-java // so have to convert to a non alpha type BufferedImage noAlpha; if (image.awt().getColorModel().hasAlpha()) { noAlpha = image.toImmutableImage().removeTransparency(java.awt.Color.WHITE).toNewBufferedImage(BufferedImage.TYPE_INT_RGB); } else { noAlpha = image.awt(); } MemoryCacheImageOutputStream output = new MemoryCacheImageOutputStream(out); writer.setOutput(output); writer.write(null, new IIOImage(noAlpha, null, null), params); output.close(); writer.dispose(); // IOUtils.closeQuietly(out); }