Package net.xoetrope.optional.laf.synth.batik

Source Code of net.xoetrope.optional.laf.synth.batik.PngTranscoderWrapper

package net.xoetrope.optional.laf.synth.batik;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import net.xoetrope.optional.laf.ImageConverter;
import org.apache.batik.transcoder.TranscoderException;

import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;

/**
* Wrap the Batik PNGTranscoder to support dynamic loading
* <p>Copyright (c) Xoetrope Ltd., 2001-2005<br>
* License:      see license.txt
* $Revision: 1.3 $
*/
public class PngTranscoderWrapper implements ImageConverter
{
  /**
   * Convert one image format to another
   * @param is the input stream for the source image
   * @param os the output  steam for the resulting/converted image
   * @param width the desired image width
   * @param height the desired image height
   * @return true for successful conversion, false otherwise
   */
  public boolean convert( String name, InputStream is, OutputStream os, int width, int height )
  {
    try {
      PNGTranscoder trans = new PNGTranscoder();
      trans.addTranscodingHint( PNGTranscoder.KEY_WIDTH, new Float( width ));
      trans.addTranscodingHint( PNGTranscoder.KEY_HEIGHT, new Float( height ));           
      TranscoderInput input = new TranscoderInput( is );
      TranscoderOutput output = new TranscoderOutput( os );
      trans.transcode( input, output );
      os.flush();
      os.close();
    }
    catch ( NoClassDefFoundError e ) { 
        e.printStackTrace();
      return false;
    }
    catch ( TranscoderException e ) {     
      return false;
    }
    catch ( IOException e ) {     
      return false;
    }
    return true;
  }

  /**
   * Get the extension of the file type that this converter produces
   */
  public String getOutputExt()
  {
    return ".png";
  }
}
TOP

Related Classes of net.xoetrope.optional.laf.synth.batik.PngTranscoderWrapper

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.