Package javax.imageio

Examples of javax.imageio.ImageWriteParam


            if (formatName.toLowerCase().equals("gif")) {
                formatName = "png";
            }
            Iterator<ImageWriter> writerIter = ImageIO.getImageWritersByFormatName(formatName);
            ImageWriter writer = writerIter.next();
            ImageWriteParam iwp = writer.getDefaultWriteParam();

            if (formatName.toLowerCase().equals("jpeg") || formatName.toLowerCase().equals("jpg")) {
                iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                iwp.setCompressionQuality(compressionQuality);
            }

            MemoryCacheImageOutputStream output = new MemoryCacheImageOutputStream(bos);
            writer.setOutput(output);
View Full Code Here


            Graphics graphics = dest.getGraphics();
            graphics.setColor(Color.WHITE);
            graphics.fillRect(0, 0, w, h);
            graphics.drawImage(srcSized, 0, 0, null);
            ImageWriter writer = ImageIO.getImageWritersByMIMEType(mimeType).next();
            ImageWriteParam params = writer.getDefaultWriteParam();
            FileImageOutputStream toFs = new FileImageOutputStream(to);
            writer.setOutput(toFs);
            IIOImage image = new IIOImage(dest, null, null);
            writer.write(null, image, params);
            toFs.flush();
View Full Code Here

            Graphics graphics = dest.getGraphics();
            graphics.setColor(Color.WHITE);
            graphics.fillRect(0, 0, width, height);
            graphics.drawImage(croppedImage, 0, 0, null);
            ImageWriter writer = ImageIO.getImageWritersByMIMEType(mimeType).next();
            ImageWriteParam params = writer.getDefaultWriteParam();
            writer.setOutput(new FileImageOutputStream(to));
            IIOImage image = new IIOImage(dest, null, null);
            writer.write(null, image, params);

        } catch (Exception e) {
View Full Code Here

        writer = iter.next();
      }
      if (writer == null) throw new IOException("no writer for format ["+format+"] available, available writer formats are ["+ListUtil.arrayToList(ImageUtil.getWriterFormatNames(), ",")+"]");
     
     
    ImageWriteParam iwp=null;
      if("jpg".equalsIgnoreCase(format)) {
        ColorModel cm = im.getColorModel();
        if(cm.hasAlpha())im=jpgImage(im);
        JPEGImageWriteParam jiwp = new JPEGImageWriteParam(Locale.getDefault());
        jiwp.setOptimizeHuffmanTables(true);
View Full Code Here

       
        private void writeImageToFile(BufferedImage image, TFile file) throws IOException {
            Iterator iter = ImageIO.getImageWritersByFormatName("jpg");

            ImageWriter writer = (ImageWriter) iter.next();
            ImageWriteParam iwp = writer.getDefaultWriteParam();
            iwp.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            iwp.setCompressionQuality(0.96f);

            File tempFile = new File(Constants.IO.imageBaseDir + File.separator + image.hashCode() + file.getName());
            FileImageOutputStream output = new FileImageOutputStream(tempFile);
            writer.setOutput(output);
            IIOImage image2 = new IIOImage(image, null, null);
View Full Code Here

                                 ImageWriter writer,
                                 OutputStream out,
                                 IIOImage image)
           throws IOException
   {
      ImageWriteParam param;
      if (mediaType.equals(MediaType.valueOf("image/jpeg")))
      {
         param = new JPEGImageWriteParam(Locale.US);
      }
      else
      {
         param = writer.getDefaultWriteParam();
      }

      /*
      * If the image output type supports compression, set it to the highest
      * maximum
      */
      ImageWriterParams writerParams =
              FindAnnotation.findAnnotation(annotations, ImageWriterParams.class);
      if (writerParams != null)
      {
         if (param.canWriteCompressed())
         {
            param.setCompressionMode(writerParams.compressionMode());
            param.setCompressionQuality(writerParams.compressionQuality());
         }
      }
      else if (param.canWriteCompressed())
      {
         param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
         param.setCompressionQuality(1.0f);
      }
      BufferedOutputStream buff = new BufferedOutputStream(out, 2048);
      ImageOutputStream ios = ImageIO.createImageOutputStream(buff);
      try
      {
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

        baos.reset();
      }
      writer.setOutput(ImageIO.createImageOutputStream(baos));

      // Create a new empty metadata set
      ImageWriteParam metaImageWriteParam = writeParam;
      if (writer instanceof JPEGImageWriter) {
        // There is an issue in the javax code because of which function call
        // writer.getDefaultImageMetadata(new ImageTypeSpecifier(image.getColorModel(),
        //    image.getSampleModel()), writeParam);
        //
View Full Code Here

    private static byte[] bufferedImageToJPEG(BufferedImage bufferedImage, float quality)
        throws Exception
    {
        ImageWriter writer = ImageIO.getImageWritersByFormatName("jpeg").next();
        ImageWriteParam writeParam = writer.getDefaultWriteParam();
        ColorModel colorModel = new DirectColorModel(24, 0x00ff0000, 0x0000ff00, 0x000000ff);
        ImageTypeSpecifier imageTypeSpecifier =
            new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(1, 1)/*ignored*/);
        writeParam.setDestinationType(imageTypeSpecifier);
        writeParam.setSourceBands(new int[] {0, 1, 2});
        writeParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        writeParam.setCompressionQuality(quality);

        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        writer.setOutput(new MemoryCacheImageOutputStream(buffer));

        IIOImage ioImage = new IIOImage(bufferedImage, null, null);
View Full Code Here

                iiowriter.addIIOWriteWarningListener(this);

                ImageOutputStream imgout = null;
                try {
                    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

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.