Package javax.imageio

Examples of javax.imageio.ImageWriter


                    file.delete();
                BufferedImage bi = getBufferedImage(img, ifd, scaleFactor);
                Iterator iter = ImageIO.getImageWritersByMIMEType("image/jpeg");
                if (iter.hasNext())
                {
                    ImageWriter writer = (ImageWriter)iter.next();
                    if (Main.m_settings.isDebug())
                        System.err.println(writer.getClass().getName());
                    ImageWriteParam iwp = writer.getDefaultWriteParam();
                    iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                    iwp.setCompressionQuality((float)quality);
                    if (bOptimizedHuffman && iwp instanceof JPEGImageWriteParam)
                    {
                        JPEGImageWriteParam iwpjpeg = (JPEGImageWriteParam)iwp;
                        // this can reduce size, but can also break badly written decoders
                        iwpjpeg.setOptimizeHuffmanTables(true);
                    }
                    writer.setOutput(fios = new FileImageOutputStream(file));
                    writer.write(null, new IIOImage(bi, null, null), iwp);
                    writer.dispose();
                    flag = true;
                }
            }
            catch(IOException ex)
            {
View Full Code Here


                    file.delete();
                BufferedImage bi = getBufferedImage(img, ifd, scaleFactor);
                Iterator iter = ImageIO.getImageWritersByMIMEType("image/bmp");
                if (iter.hasNext())
                {
                    ImageWriter writer = (ImageWriter)iter.next();
                    if (Main.m_settings.isDebug())
                        System.err.println(writer.getClass().getName());
                    writer.setOutput(fios = new FileImageOutputStream(file));
                    writer.write(new IIOImage(bi, null, null));
                    writer.dispose();
                    flag = true;
                }
            }
            catch(IOException ex)
            {
View Full Code Here

                }
                List pages = document.getDocumentCatalog().getAllPages();
                for( int i=startPage-1; i<endPage && i<pages.size(); i++ )
                {
                    ImageOutputStream output = null;
                    ImageWriter imageWriter = null;
                    try
                    {
                        PDPage page = (PDPage)pages.get( i );
                        BufferedImage image = page.convertToImage();
                        String fileName = outputPrefix + (i+1) + "." + imageType;
                        System.out.println( "Writing:" + fileName );
                        output = ImageIO.createImageOutputStream( new File( fileName ) );
                       
                        boolean foundWriter = false;
                        Iterator writerIter = ImageIO.getImageWritersByFormatName( imageType );
                        while( writerIter.hasNext() && !foundWriter )
                        {
                            try
                            {
                                imageWriter = (ImageWriter)writerIter.next();
                                ImageWriteParam writerParams = imageWriter.getDefaultWriteParam();
                                if(writerParams.canWriteCompressed() )
                                {
                                    writerParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                                    writerParams.setCompressionQuality(1.0f);
                                }
                               
                               
                                imageWriter.setOutput( output );
                                imageWriter.write( null, new IIOImage( image, null, null), writerParams );
                                foundWriter = true;
                            }
                            catch( IIOException io )
                            {
                                //ignore exception
                            }
                            finally
                            {
                                if( imageWriter != null )
                                {
                                    imageWriter.dispose();
                                }
                            }
                        }
                        if( !foundWriter )
                        {
View Full Code Here

   * @param quality
   *            质量 0.1f ~ 1.0f
   */
  public static void writeJpeg(RenderedImage im, File targetJpg, float quality) {
    try {
      ImageWriter writer = ImageIO.getImageWritersBySuffix("jpg").next();
      ImageWriteParam param = writer.getDefaultWriteParam();
      param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
      param.setCompressionQuality(quality);
      ImageOutputStream os = ImageIO.createImageOutputStream(targetJpg);
      writer.setOutput(os);
      writer.write((IIOMetadata) null, new IIOImage(im, null, null), param);
    }
    catch (IOException e) {
      throw Lang.wrapThrow(e);
    }
  }
View Full Code Here

     * @throws Exception if an error prevents image encoding
     */
    public void saveImage(String mimeType, BufferedImage image, OutputStream os)
            throws Exception {

        ImageWriter writer = null;
        Iterator iter = javax.imageio.ImageIO.getImageWritersByMIMEType(mimeType);
        if (iter.hasNext()) {
            writer = (ImageWriter) iter.next();
        }
        ImageOutputStream ios = javax.imageio.ImageIO.createImageOutputStream(os);
        writer.setOutput(ios);

        writer.write(new IIOImage(image, null, null));
        ios.flush();
        writer.dispose();
    } // saveImage
View Full Code Here

                // peeves in JAXB RI as well, so if you fix this, submit the
                // code to the JAXB RI as well (see RuntimeBuiltinLeafInfoImpl)! - DD
                ByteArrayOutputStream bos = new ByteArrayOutputStream(2048);
                Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(ct);
                if (writers.hasNext()) {
                    ImageWriter writer = writers.next();
                   
                    try {
                        BufferedImage bimg = convertToBufferedImage((Image) o);
                        ImageOutputStream out = ImageIO.createImageOutputStream(bos);
                        writer.setOutput(out);
                        writer.write(bimg);
                        writer.dispose();
                        out.flush();
                        out.close();
                        bos.close();
                    } catch (IOException e) {
                        throw new Fault(e);
View Full Code Here

            if (!i.hasNext()) {
                mimeType = "image/jpeg";
                i = ImageIO.getImageWritersByMIMEType(mimeType);
            }

            ImageWriter writer = i.next();

            ByteArrayOutputStream os = new ByteArrayOutputStream();
            writer.setOutput(new MemoryCacheImageOutputStream(os));
            writer.write(image);
            image.flush();
            image = null;
            resultStream = new ByteArrayInputStream(os.toByteArray());
        } else {
            resultStream = imageStream;
View Full Code Here

        // Create output stream
        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        String format = config.getImageFormat().substring(1);
        // Get image writer for format
        // FIXME: config.getImageFormat()
        final ImageWriter writer = (ImageWriter) ImageIO
                .getImageWritersByFormatName(format).next();

        // Write out image
        writer.setOutput(ImageIO.createImageOutputStream(out));
        writer.write(image);

        // Return the image data
        return out.toByteArray();
    }
View Full Code Here

    final BufferedImage rendImage = createRenderedImage();
    boolean success = false;

    try {
      final ImageWriteParam iwparam   = new JPEGImageWriteParam(Locale.getDefault());
      final ImageWriter iw       = ImageIO.getImageWritersByFormatName("jpg").next();//$NON-NLS-1$
      try(final ImageOutputStream ios = ImageIO.createImageOutputStream(file)){
        iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwparam.setCompressionQuality(1f-dialogueBox.getCompressionRate()/100f);
        iw.setOutput(ios);
        iw.write(null, new IIOImage(rendImage, null, null), iwparam);
        iw.dispose();
        success = true;
      }
      }catch(final IOException e) { BadaboomCollector.INSTANCE.add(e); }
    rendImage.flush();
    return success;
View Full Code Here

    final BufferedImage rendImage = createRenderedImage();
    boolean success = false;

    try {
      final ImageWriteParam iwparam  = new BMPImageWriteParam();
      final ImageWriter iw      = ImageIO.getImageWritersByFormatName("bmp").next();//$NON-NLS-1$
      try(final ImageOutputStream ios  = ImageIO.createImageOutputStream(file)) {
        iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iw.setOutput(ios);
        iw.write(null, new IIOImage(rendImage, null, null), iwparam);
        iw.dispose();
        success = true;
      }
      }catch(final IOException e) { BadaboomCollector.INSTANCE.add(e); }
    rendImage.flush();
    return success;
View Full Code Here

TOP

Related Classes of javax.imageio.ImageWriter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.