Examples of ImageWriter


Examples of ae.javax.imageio.ImageWriter

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        IOException ioe = null;

        while (writerIterator.hasNext()) {
            ImageWriter imageWriter = (ImageWriter)writerIterator.next();
            ImageWriterSpi writerSpi = imageWriter.getOriginatingProvider();

            if (!writerSpi.canEncodeImage(typeSpecifier)) {
                continue;
            }

            try {
                ImageOutputStream imageOutputStream =
                    ImageIO.createImageOutputStream(baos);
                try {
                    imageWriter.setOutput(imageOutputStream);
                    imageWriter.write(renderedImage);
                    imageOutputStream.flush();
                } finally {
                    imageOutputStream.close();
                }
            } catch (IOException e) {
                imageWriter.dispose();
                baos.reset();
                ioe = e;
                continue;
            }

            imageWriter.dispose();
            baos.close();
            return baos.toByteArray();
        }

        baos.close();
View Full Code Here

Examples of com.google.code.appengine.imageio.ImageWriter

            // set our parameters
            properties.setProperty(formatKey + ANTIALIAS, true);
            properties.setProperty(formatKey + ANTIALIAS_TEXT, true);

            // copy parameters from specific format
            ImageWriter writer = getPreferredImageWriter(format);
            if (writer != null) {
                ImageWriteParam param = writer.getDefaultWriteParam();

                // compression
                if (param.canWriteCompressed()) {
                    param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
                    properties.setProperty(formatKey + COMPRESS, true);
View Full Code Here

Examples of com.volantis.map.ics.imageprocessor.writer.ImageWriter

        // if there is no destination rule in parameter block it means
        // that we should just pass the input into output.
        if (params.containsName(ParameterNames.DESTINATION_FORMAT_RULE)) {
           // ImageReader reader = null;
            ImageWriter writer = null;
            Pipeline pipeline = null;

            String rule = null;
            try {
                rule = params.getParameterValue(ParameterNames.DESTINATION_FORMAT_RULE);
                writer = theImageWriterFactory.
                    getWriter(rule, params);
            } catch (Exception e) {
                LOGGER.error("instantiating-error",
                        new String[] { "image writer", rule });
                throw new ImageProcessorException(e);
            }
            if (writer == null) {
                String msg = EXCEPTION_LOCALIZER.format("instantiating-error",
                        new String[] { "image writer", rule });
                throw new ImageProcessorException(msg);
            }

            try {
                // Build up processing pipeline.
                pipeline = new Pipeline();

                //Add cropping tool. when there are
                //all needed parameters, otherwise
                // tool will not be used
                if (params.containsName(ParameterNames.LEFT_X) &&
                    params.containsName(ParameterNames.RIGHT_X) &&
                    params.containsName(ParameterNames.BOTTOM_Y) &&
                    params.containsName(ParameterNames.TOP_Y)) {
                    Tool croppingTool =
                        theToolFactory.getTool("CroppingTool");
                    pipeline.addTool(croppingTool);
                }


                // We should guarantee that all other tools works
                // with RGB(A) images. However we have an optimized path for
                // writing Indexed images as GIFs. The RGB converter tool won't
                // do anything in that case unless watermarking is required in
                // which case we take the slow route.
                pipeline.addTool(theToolFactory.getTool("RGBConverterTool"));

                // Add clipping tool if it is needed.
                if (params.containsName(ParameterNames.PRESERVE_X_LEFT) ||
                    params.containsName(ParameterNames.PRESERVE_X_RIGHT)) {
                    Tool clippingTool =
                        theToolFactory.getTool("ClippingTool");
                    pipeline.addTool(clippingTool);
                }

                // Add resizing tool if it is needed.
                if (params.containsName(ParameterNames.IMAGE_WIDTH)) {
                    Tool resizingTool =
                        theToolFactory.getTool("ResizingTool");
                    pipeline.addTool(resizingTool);
                }

               
                //Add watermarking tool.
                if (params.containsName(ParameterNames.WATERMARK_URL)) {
                    Tool watermarkingTool =
                        theToolFactory.getTool("WatermarkingTool");
                    pipeline.addTool(watermarkingTool);
                }

                RenderedOp[] ops = null;
                ops = ImageReader.loadImage(inputData);

                // hack to get around incorrect behaviour associated with
                // the scale operation vbm.2004121009
                // if source has an indexed colour model and has a
                // transparency which is not OPAQUE and has an Alpha then
                // switch back to nearest neighbour interpolation for the
                // scaling.
                if (ops.length > 0)
                {
                    ColorModel colorModel = ops[0].getColorModel();
                    if (colorModel.hasAlpha() && colorModel.getTransparency()
                                                 != ColorModel.OPAQUE) {
                        if (LOGGER.isDebugEnabled()) {
                            LOGGER.debug("Resetting scale mode to " +
                                         "SCALE_MODE_NEAREST");
                        }
                        params.setParameterValue(
                            ParameterNames.SCALE_MODE,
                            Integer.toString(ImageConstants.SCALE_MODE_NEAREST));
                    }
                }

                // Run the pipeline and process images.
                ops = pipeline.process(ops, params);

                // Write images into chosen format.
                    outputData.mark();
                outputData = writer.process(ops, params, outputData);
            } catch (Exception e) {
                LOGGER.error("processor-failure");
                throw new ImageProcessorException(e);
            }
        } else {
View Full Code Here

Examples of javax.imageio.ImageWriter

        int pos = filename.lastIndexOf('.');
        if (pos != -1) {
            String extension = filename.substring(pos + 1, filename.length()).toLowerCase();

            // Find a writer for that file suffix
            ImageWriter writer = null;
            Iterator iter = ImageIO.getImageWritersBySuffix(extension);
            if (iter.hasNext())
                writer = (ImageWriter)iter.next();
            if (writer != null) {
                ImageOutputStream ios = null;
                try {
                    // Prepare output file
                    File file = new File(filename);
                    if (file.exists())
                        file.delete();
                    ios = ImageIO.createImageOutputStream(file);
                    writer.setOutput(ios);
                    this.write(wrapper, writer, quality, alpha);
                 } finally {
                    if (ios != null)
                        ios.close();
                    writer.dispose();
                }
            }
        }
    }
View Full Code Here

Examples of javax.imageio.ImageWriter

     * @throws IOException
     * @see helma.image.ImageGenerator#write(helma.image.ImageWrapper, java.io.OutputStream, java.lang.String, float, boolean)
     */
    public void write(ImageWrapper wrapper, OutputStream out, String mimeType, float quality, boolean alpha) throws IOException {
            // Find a writer for that type
        ImageWriter writer = null;
        Iterator iter = ImageIO.getImageWritersByMIMEType(mimeType);
        if (iter.hasNext())
            writer = (ImageWriter)iter.next();
        if (writer != null) {
            ImageOutputStream ios = null;
            try {
                ios = ImageIO.createImageOutputStream(out);
                writer.setOutput(ios);
                this.write(wrapper, writer, quality, alpha);
            } finally {
                if (ios != null)
                    ios.close();
                writer.dispose();
            }
        }
   }
View Full Code Here

Examples of javax.imageio.ImageWriter

          if (mimeType == null || mimeType.startsWith("image/*"))
            mimeType = "image/png";
          Iterator<ImageWriter> itr = ImageIO
              .getImageWritersByMIMEType(mimeType);
          if (itr.hasNext()) {
            ImageWriter w = itr.next();
                        w.setOutput(ImageIO.createImageOutputStream(output));
            w.write(convertToBufferedImage((Image)value));
            w.dispose();
          } else {
            // LOG no handler
          }
        }else if(DataHandler.class.isAssignableFrom(value.getClass())){
          ((DataHandler)value).writeTo(output);
View Full Code Here

Examples of javax.imageio.ImageWriter

   * @param data
   * @return the number if bytes written in the array
   * @throws IOException
   */
  protected static int writeJPEG(BufferedImage image,byte[] data) throws IOException {
    ImageWriter iw = (ImageWriter)ImageIO.getImageWritersByMIMEType("image/jpeg").next();
    ImageWriteParam iwParam = iw.getDefaultWriteParam();
    float quality = .8f;
    iwParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
    iwParam.setCompressionQuality(quality);
    CustomByteArrayOutputStream out = new CustomByteArrayOutputStream(data);
    iw.setOutput(out);
   
    IIOImage img = new IIOImage(image, null, null);
   
    iw.write(null, img, iwParam);
    return out.getBytesWritten();
  }
View Full Code Here

Examples of javax.imageio.ImageWriter

        param.setCompressionQuality(0.74f);
            // param.setQuality(0.74f, true);

            final ByteArrayOutputStream os = new ByteArrayOutputStream();
            MemoryCacheImageOutputStream out = new MemoryCacheImageOutputStream(os);
            ImageWriter encoder = (ImageWriter)ImageIO.getImageWritersByFormatName("JPEG").next();
            // final JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(os, param);
        encoder.setOutput(out);
        encoder.write(null, new IIOImage(image, null, null), param);
            // jpeg.encode(image);

        out.close();
            os.close();
View Full Code Here

Examples of javax.imageio.ImageWriter

    * @return
    */
   public static ImageWriter getImageWriterByMediaType(MediaType mediaType)
   {
      Iterator<ImageWriter> writers = ImageIO.getImageWritersByMIMEType(mediaType.toString());
      ImageWriter writer = writers.next();
      if (writer == null)
      {
         Response response = Response.serverError().entity("").build();
         throw new WebApplicationException(response);
      }
View Full Code Here

Examples of javax.imageio.ImageWriter

    try{
      final Iterator<ImageWriter> it = ImageIO.getImageWritersByFormatName("jpeg"); //$NON-NLS-1$
     
      if (it.hasNext()){
        final ImageWriter writer = it.next();
       
        final ImageOutputStream ios = new FileImageOutputStream(new File(sDest));
       
        writer.setOutput(ios);
       
        final JPEGImageWriteParam iwParam = new JPEGImageWriteParam(Locale.getDefault());
        iwParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
        iwParam.setCompressionQuality(quality);
       
        writer.write(null, new IIOImage(dest, null, null), iwParam);
       
        ios.flush();
        ios.close();
      }
      else{
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.