Package org.apache.batik.transcoder.image

Examples of org.apache.batik.transcoder.image.ImageTranscoder


    /**
     * Returns the <tt>ImageTranscoder</tt> the Test should
     * use
     */
    public ImageTranscoder getTestImageTranscoder(){
        ImageTranscoder t = new InternalPNGTranscoder();
        t.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE,
                             Boolean.FALSE);
        t.addTranscodingHint(PNGTranscoder.KEY_BACKGROUND_COLOR,
                             new Color(0,0,0,0));
        t.addTranscodingHint(PNGTranscoder.KEY_EXECUTE_ONLOAD,
                             Boolean.TRUE);

        if (validate){
            t.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_VALIDATING,
                                 Boolean.TRUE);
            t.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_CLASSNAME,
                                 VALIDATING_PARSER);
        }

        if (userLanguage != null){
            t.addTranscodingHint(PNGTranscoder.KEY_LANGUAGE,
                                 userLanguage);
        }
        return t;
    }
View Full Code Here


                                           SVGRenderingAccuracyTest.TEMP_FILE_SUFFIX);
       
        TranscoderOutput validDst
            = new TranscoderOutput(new FileOutputStream(tmpFile));
       
        ImageTranscoder transcoder
            = new PNGTranscoder();
       
        transcoder.transcode(validSrc, validDst);
       
        tmpFile.deleteOnExit();
       
        return tmpFile.toURL();
    }
View Full Code Here

    /**
     * Returns the <tt>ImageTranscoder</tt> the Test should
     * use
     */
    public ImageTranscoder getTestImageTranscoder(){
        ImageTranscoder t = super.getTestImageTranscoder();
        t.addTranscodingHint(PNGTranscoder.KEY_ALTERNATE_STYLESHEET,
                             parameter);
        return t;
    }
View Full Code Here

    /**
     * Returns the <tt>ImageTranscoder</tt> the Test should
     * use
     */
    public ImageTranscoder getTestImageTranscoder(){
        ImageTranscoder t = super.getTestImageTranscoder();
        t.addTranscodingHint(PNGTranscoder.KEY_MEDIA, parameter);
        return t;
    }
View Full Code Here

                        (resources.getString("Message.exportAsPNG"));

                    // create a BufferedImage of the appropriate type
                    int w = buffer.getWidth();
                    int h = buffer.getHeight();
                    final ImageTranscoder trans = new PNGTranscoder();
                    if (application.getXMLParserClassName() != null) {
                        trans.addTranscodingHint
                            (JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
                                application.getXMLParserClassName());
                    }
                    trans.addTranscodingHint(PNGTranscoder.KEY_FORCE_TRANSPARENT_WHITE,
                                             Boolean.TRUE );

            // Start: By Jun Inamori
            if(isIndexed){
                trans.addTranscodingHint(PNGTranscoder.KEY_INDEXED,new Integer(256));
            }
            // End: By Jun Inamori

                    final BufferedImage img = trans.createImage(w, h);

                    // paint the buffer to the image
                    Graphics2D g2d = img.createGraphics();
                    g2d.drawImage(buffer, null, 0, 0);
                    new Thread() {
                        public void run() {
                            try {
                                currentSavePath = f;
                                OutputStream ostream =
                                    new BufferedOutputStream(new FileOutputStream(f));
                                trans.writeImage(img,
                                                 new TranscoderOutput(ostream));
                                ostream.close();
                            } catch (Exception ex) {}
                            statusBar.setMessage
                                (resources.getString("Message.done"));
View Full Code Here

                        (resources.getString("Message.exportAsTIFF"));

                    // create a BufferedImage of the appropriate type
                    int w = buffer.getWidth();
                    int h = buffer.getHeight();
                    final ImageTranscoder trans = new TIFFTranscoder();
                    if (application.getXMLParserClassName() != null) {
                        trans.addTranscodingHint
                            (JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
                                application.getXMLParserClassName());
                    }
                    final BufferedImage img = trans.createImage(w, h);

                    // paint the buffer to the image
                    Graphics2D g2d = img.createGraphics();
                    g2d.drawImage(buffer, null, 0, 0);
                    new Thread() {
                        public void run() {
                            try {
                                currentSavePath = f;
                                OutputStream ostream = new BufferedOutputStream
                                    (new FileOutputStream(f));
                                trans.writeImage
                                    (img, new TranscoderOutput(ostream));
                                ostream.close();
                            } catch (Exception ex) {}
                            statusBar.setMessage
                                (resources.getString("Message.done"));
View Full Code Here

                        (resources.getString("Message.exportAsJPG"));

                    // create a BufferedImage of the appropriate type
                    int w = buffer.getWidth();
                    int h = buffer.getHeight();
                    final ImageTranscoder trans = new JPEGTranscoder();
                    if (application.getXMLParserClassName() != null) {
                        trans.addTranscodingHint
                            (JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
                                application.getXMLParserClassName());
                    }
                    trans.addTranscodingHint
                        (JPEGTranscoder.KEY_QUALITY, new Float(quality));

                    final BufferedImage img = trans.createImage(w, h);

                    // paint the buffer to the image
                    Graphics2D g2d = img.createGraphics();
                    g2d.setColor(Color.white);
                    g2d.fillRect(0, 0, w, h);
                    g2d.drawImage(buffer, null, 0, 0);
                    new Thread() {
                        public void run() {
                            try {
                                currentSavePath = f;
                                OutputStream ostream =
                                    new BufferedOutputStream(new FileOutputStream(f));
                                trans.writeImage(img, new TranscoderOutput(ostream));
                                ostream.close();
                            } catch (Exception ex) { }
                            statusBar.setMessage
                                (resources.getString("Message.done"));
                        }
View Full Code Here

                                           SVGRenderingAccuracyTest.TEMP_FILE_SUFFIX);
       
        TranscoderOutput validDst
            = new TranscoderOutput(new FileOutputStream(tmpFile));
       
        ImageTranscoder transcoder
            = new PNGTranscoder();
       
        transcoder.transcode(validSrc, validDst);
       
        tmpFile.deleteOnExit();
       
        return tmpFile.toURL();
    }
View Full Code Here

        try {

            TranscoderInput input = new TranscoderInput(dom);

            ImageTranscoder t = new ImageTranscoder() {

                @Override
                public BufferedImage createImage(int w, int h) {
                    return new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
                }

                @Override
                public void writeImage(BufferedImage image, TranscoderOutput out)
                        throws TranscoderException {
                    int wd = image.getWidth() / 2;
                    int ht = image.getHeight() / 2;
                    BufferedImage resizedImage = new BufferedImage(wd, ht, BufferedImage.TYPE_INT_ARGB);
                    Graphics2D g = resizedImage.createGraphics();
                    g.setComposite(AlphaComposite.Src);
                    g.setRenderingHint(RenderingHints.KEY_INTERPOLATION,RenderingHints.VALUE_INTERPOLATION_BILINEAR);
                    g.setRenderingHint(RenderingHints.KEY_RENDERING,RenderingHints.VALUE_RENDER_QUALITY);
                    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
                    g.drawImage(image, 0, 0, wd, ht, null);
                    g.dispose();
                    imagePointer[0] = resizedImage;
                }
              };
            t.setTranscodingHints(transcoderHints);
            t.transcode(input, null);
        }
        catch (TranscoderException ex) {
            // Requires Java 6
            ex.printStackTrace();
            throw new IOException("Couldn't convert SVG");
View Full Code Here

  }

  private static byte[] getRasterImageByteArray(final Document document, final int width, final ImageFormat imageFormat)
  {
    // Create a image transcoder
    final ImageTranscoder t;
    if (imageFormat == ImageFormat.JPEG) {
      t = new JPEGTranscoder();
      t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(.8));
      t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(width));
      // } else if (imageFormat == ImageFormat.TIFF) {
      // t = new TIFFTranscoder();
      // t.addTranscodingHint(TIFFTranscoder.KEY_WIDTH, new Float(width));
    } else {
      t = new PNGTranscoder();
      t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(width));
    }
    // Set the transcoding hints.
    TranscoderInput input = new TranscoderInput(document);
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final TranscoderOutput output = new TranscoderOutput(baos);
    // Save the image.
    try {
      t.transcode(input, output);
    } catch (TranscoderException ex) {
      log.fatal("Exception encountered " + ex, ex);
    }
    return baos.toByteArray();
  }
View Full Code Here

TOP

Related Classes of org.apache.batik.transcoder.image.ImageTranscoder

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.