Package javax.imageio

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


     * @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

          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

   * @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

        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

    * @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

    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

//          encoder.setJPEGEncodeParam(encpar);
//          encoder.encode(image);
         
          ByteArrayOutputStream out = new ByteArrayOutputStream();
         
          ImageWriter writer = ImageIO.getImageWritersByFormatName( "jpg" ).next();
            ImageOutputStream ios = ImageIO.createImageOutputStream( out );
            writer.setOutput( ios );
           
           
            //ImageWriteParam param = writer.getDefaultWriteParam();
           
            //log.debug("Logs "+param.getCompressionType());
           
            //param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
            //param.setCompressionQuality(ClientConnectionBean.imgQualityDefault);

           
            ImageWriteParam iwparam = new JPEGImageWriteParam( Locale.getDefault() );
            iwparam.setCompressionMode( ImageWriteParam.MODE_EXPLICIT ) ;
            iwparam.setCompressionQuality( ClientConnectionBean.imgQualityDefault );
            writer.write( null, new IIOImage(image, null, null), null );
           
            ios.flush();
            writer.dispose();
            ios.close();
         
          imageScreen.flush();
         
          byte[] payload = out.toByteArray();
View Full Code Here

          Graphics2D biContext = image.createGraphics();
          biContext.drawImage(img, 0, 0, null);
         
          ByteArrayOutputStream out = new ByteArrayOutputStream();
         
          ImageWriter writer = ImageIO.getImageWritersByFormatName( "gif" ).next();
            ImageOutputStream ios = ImageIO.createImageOutputStream( out );
            writer.setOutput( ios );
           
            writer.write( null, new IIOImage(image, null, null), null );
           
            ios.flush();
            writer.dispose();
            ios.close();
         
          imageScreen.flush();
         
          byte[] payload = out.toByteArray();
View Full Code Here

          Image image = getPreviewImage().getImage();
          if (image instanceof RenderedImage) {
            Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix(extension);
            if (writers.hasNext()) {
              ImageWriter writer = writers.next();
              writer.setOutput(ImageIO.createImageOutputStream(selectedFile));
              writer.write((RenderedImage) image);
            } else {
              // should never happen
              LOG.error(GettextResource.gettext(Configuration.getInstance().getI18nResourceBundle(),
                  "Unable to save image"));
            }
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.