Package javax.imageio

Examples of javax.imageio.ImageWriteParam


        public void writeImage(RenderedImage image, ImageWriterParams params) throws IOException {
            if (iiowriter == null) {
                throw new IllegalStateException("MultiImageWriter already closed!");
            }
            ImageWriteParam iwParam = getDefaultWriteParam(iiowriter, image, params);

            ImageTypeSpecifier type;
            if (iwParam.getDestinationType() != null) {
                type = iwParam.getDestinationType();
            } else {
                type = ImageTypeSpecifier.createFromRenderedImage(image);
            }

            //Handle metadata
View Full Code Here


        // obtain the writer for the image
        // this must work since it is already done in the #getImageType(String) call above
        ImageWriter writer = (ImageWriter)ImageIO.getImageWritersByFormatName(formatName).next();

        // get default image writer parameter
        ImageWriteParam param = writer.getDefaultWriteParam();
        if (param.canWriteCompressed()) {
            // set compression parameters if supported by writer
            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            if ((param.getCompressionTypes() != null) && (param.getCompressionType() == null)) {
                // a compression parameter is required but not provided, use the first one available
                param.setCompressionType(param.getCompressionTypes()[0]);
            }
            param.setCompressionQuality(m_renderSettings.getCompressionQuality());
        }

        // now write the image
        writer.setOutput(stream);
        writer.write(null, new IIOImage(im, null, null), param);
View Full Code Here

      File fo = new File(name);
      ImageOutputStream ios = ImageIO.createImageOutputStream(fo);
      w.setOutput(ios);
      ImageWriteParam iwparam = w.getDefaultWriteParam();
                iwparam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT) ;
                iwparam.setCompressionQuality(1.0F);

      w.write(null, new IIOImage(image, null, null), iwparam);
      //w.write((BufferedImage) image,iwparam);
      System.out.println("File " + name + " written");
      ret = true;
View Full Code Here

    try {
      Controller.getCurrentController().getViewController().setWaitingCursor(true);
      Iterator<ImageWriter> imageWritersByFormatName = ImageIO.getImageWritersByFormatName(imageType);
      for(;;){
        ImageWriter writer = imageWritersByFormatName.next();
        ImageWriteParam writeParam = writer.getDefaultWriteParam();
        ImageTypeSpecifier typeSpecifier = ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
        IIOMetadata metadata = writer.getDefaultImageMetadata(typeSpecifier, writeParam);
        if ((metadata.isReadOnly() || !metadata.isStandardMetadataFormatSupported()) && imageWritersByFormatName.hasNext()) {
          continue;
                }
View Full Code Here

     *            质量 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) {
View Full Code Here

        }
        return irp;
    }

    protected static ImageWriteParam _getIWP(ImageWriter w, Dimension srcDim, String mime, int bufferedType, float compressionQuality) {
        ImageWriteParam iwp = w.getDefaultWriteParam();
        boolean found = false;
        for (String m : w.getOriginatingProvider().getMIMETypes()) {
            if (m.equals(mime)) {
                found = true;
                break;
            }
        }
        if (!found) {
            throw new JXAException("incompatible mime type specified " + mime + " for writer " + w.toString());
        }
        iwp.setDestinationType(_getITS(bufferedType));
        if (iwp.canWriteTiles()) {
            /*
             * if (_WRITE_TILES_DIMENSION.width < srcDim.width ||
             * _WRITE_TILES_DIMENSION.height < srcDim.height) {
             */
            /*
             * iwp.setTilingMode(iwp.MODE_EXPLICIT);
             * iwp.setTiling(_WRITE_TILES_DIMENSION.width,
             * _WRITE_TILES_DIMENSION.height, 0, 0);
             */
            /*
             * } else { iwp.setTilingMode(iwp.MODE_DISABLED); }
             */
        }
        if (iwp.canWriteCompressed()) {
            String css = ImageCollection._getCompressionType(mime, bufferedType);
            try {
                if (css != null) {
                    if (compressionQuality >= 0f) {
                        iwp.setCompressionMode(iwp.MODE_EXPLICIT);
                        iwp.setCompressionType(css);
                        iwp.setCompressionQuality(compressionQuality);
                    } else {
                        iwp.setCompressionMode(iwp.MODE_COPY_FROM_METADATA);
                    }
                } else {
                    iwp.setCompressionMode(iwp.MODE_DISABLED);
                }
            } catch (RuntimeException ex) {
                if (DebugMap._getInstance().isDebuggerEnabled(Sprite.class)) {
                    ex.printStackTrace();
                }
                try {
                    iwp.setCompressionMode(iwp.MODE_DEFAULT);
                } catch (RuntimeException ex2) {
                    if (DebugMap._getInstance().isDebuggerEnabled(Sprite.class)) {
                        ex.printStackTrace();
                    }
                }
            }
        }

        if (DebugMap._getInstance().isDebuggerEnabled(Sprite.class)) {
            System.out.print("imagewriter will use " + ImageCollection.BUFFERED_TYPE.valueOf(iwp.getDestinationType().getBufferedImageType()) + " for " + w.getOriginatingProvider().getFormatNames()[0]);
            if (iwp.canWriteCompressed()) {
                switch (iwp.getCompressionMode()) {
                    case ImageWriteParam.MODE_EXPLICIT:
                        System.out.println(" w/ " + iwp.getLocalizedCompressionTypeName());
                        break;
                    case ImageWriteParam.MODE_DEFAULT:
                        System.out.println(" w/ default compression.");
                        break;
                    default:
View Full Code Here

            throws IOException {
        ParamChecks.nullNotPermitted(bufferedImage, "bufferedImage");
        ParamChecks.nullNotPermitted(outputStream, "outputStream");
        Iterator iterator = ImageIO.getImageWritersByFormatName("jpeg");
        ImageWriter writer = (ImageWriter) iterator.next();
        ImageWriteParam p = writer.getDefaultWriteParam();
        p.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        p.setCompressionQuality(this.quality);
        ImageOutputStream ios = ImageIO.createImageOutputStream(outputStream);
        writer.setOutput(ios);
        writer.write(null, new IIOImage(bufferedImage, null, null), p);
        ios.flush();
        writer.dispose();
View Full Code Here

        if (iiowriter != null) {
            iiowriter.addIIOWriteWarningListener(this);
           
            ImageOutputStream imgout = ImageIO.createImageOutputStream(out);
           
            ImageWriteParam iwParam = getDefaultWriteParam(iiowriter, image, params);
           
            ImageTypeSpecifier type;
            if (iwParam.getDestinationType() != null) {
                type = iwParam.getDestinationType();
            } else {
                type = ImageTypeSpecifier.createFromRenderedImage(image);
            }
           
            //Handle metadata
View Full Code Here

     * @return the IIO ImageWriteParam instance
     */
    protected ImageWriteParam getDefaultWriteParam(
            javax.imageio.ImageWriter iiowriter, RenderedImage image,
            ImageWriterParams params) {
        ImageWriteParam param = iiowriter.getDefaultWriteParam();
        System.err.println("Param: " + params);
        if ((params != null) && (params.getCompressionMethod() != null)) {
            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            param.setCompressionType(params.getCompressionMethod());
        }
        return param;
    }
View Full Code Here

  protected ImageOutputter getOutputter() {
    Iterator<ImageWriter> writers = ImageIO.getImageWritersByFormatName(getOriginalFormatName());
    if (writers.hasNext()) {
      ImageWriter writer = writers.next();
      ImageWriteParam param = writer.getDefaultWriteParam();
      if (getOriginalFormatName().equals("jpeg")) {
        param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        param.setCompressionQuality(config.getJpegCompression());
        if (param instanceof JPEGImageWriteParam) {
          ((JPEGImageWriteParam) param).setOptimizeHuffmanTables(
                config.getJpegHuffmanOptimization());
        }
      }
View Full Code Here

TOP

Related Classes of javax.imageio.ImageWriteParam

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.