Examples of PNGTranscoder


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

    /**
     * Returns the <tt>ImageTranscoder</tt> the Test should
     * use
     */
    public static ImageTranscoder getImageTranscoder(){
        ImageTranscoder t = new PNGTranscoder();
        t.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_CLASSNAME,
                             PARSER_CLASS_NAME);
        return t;
    }
View Full Code Here

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

    }
  }
 
  public static void transformSVGIntoPNG (InputStream inputStream, OutputStream outputStream) {
    // create a PNG transcoder
    PNGTranscoder t = new PNGTranscoder();
   
    // set the transcoding hints
    t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(1000));
    t.addTranscodingHint(PNGTranscoder.KEY_ALLOWED_SCRIPT_TYPES, "*");
    t.addTranscodingHint(PNGTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN, new Boolean(true));
    t.addTranscodingHint(PNGTranscoder.KEY_EXECUTE_ONLOAD, new Boolean(true));
   
    // create the transcoder input
    Reader reader = new InputStreamReader(inputStream);
    TranscoderInput input = new TranscoderInput(reader);
   
    // create the transcoder output
    TranscoderOutput output = new TranscoderOutput(outputStream);
   
    // save the image
    try {
      t.transcode(input, output);
    } catch (TranscoderException e) {
      logger.error("Impossible to convert svg to jpeg: " + e.getCause(), e);
      throw new SpagoBIEngineRuntimeException("Impossible to convert svg to jpeg: " + e.getCause(), e);
    }
  }
View Full Code Here

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

              Activator.logWarning("Failed to validate "
                  + dispelFile.getName());
              return FAILED_ICON;
            }

            PNGTranscoder t = new PNGTranscoder();

            File tmpSvg = File.createTempFile(
                "dispelValidation", ".svg");
            tmpSvg.deleteOnExit();
            OutputStream os = new FileOutputStream(tmpSvg);
            os.write(graph.getBytes());
            os.flush();
            os.close();

            TranscoderInput input = new TranscoderInput(
                tmpSvg.toURI().toString());

            //Could probably be clever and use a piped stream
            //but easier just to use tmp file

            File tmpPng = File.createTempFile(
                "dispelValidation", ".png");
            tmpPng.deleteOnExit();
            os = new FileOutputStream(tmpPng);
            TranscoderOutput output = new TranscoderOutput(os);
            t.transcode(input, output);
            os.flush();
            os.close();
            ret = ImageDescriptor.createFromURL(tmpPng.toURL());
          }
        } catch (CoreException e1) {
View Full Code Here

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

            }
        } else if (transformto != null && transformto.equals(TO_PNG)) {
            try {
                if(respaction != null && respaction.equals(RESPACTION_SHOWURL)) {
                    ByteArrayOutputStream bout = new ByteArrayOutputStream();
                    PNGTranscoder t = new PNGTranscoder();
                    t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen");
                    TranscoderInput input = new TranscoderInput(new StringReader(formattedSvg));
                    TranscoderOutput output = new TranscoderOutput(bout);
                    t.transcode(input, output);
                    resp.setCharacterEncoding("UTF-8");
                    resp.setContentType("text/plain");
                    resp.getWriter().write("<img src=\"data:image/png;base64," + Base64.encodeBase64(bout.toByteArray()) + "\">");
                } else {
                    storeInRepository(uuid, rawSvg, transformto, processid, repository);
                    resp.setContentType("image/png");
                    if (processid != null) {
                        resp.setHeader("Content-Disposition", "attachment; filename=\"" + processid + ".png\"");
                    } else {
                        resp.setHeader("Content-Disposition", "attachment; filename=\"" + uuid + ".png\"");
                    }

                    PNGTranscoder t = new PNGTranscoder();
                    t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen");
                    TranscoderInput input = new TranscoderInput(new StringReader(
                            formattedSvg));
                    TranscoderOutput output = new TranscoderOutput(
                            resp.getOutputStream());
                    t.transcode(input, output);
                }
            } catch (TranscoderException e) {
                resp.sendError(500, e.getMessage());
            }
        } else if (transformto != null && transformto.equals(TO_SVG)) {
View Full Code Here

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

                    TranscoderInput input = new TranscoderInput(new StringReader(
                            rawSvg));
                    TranscoderOutput output = new TranscoderOutput(outputStream);
                    t.transcode(input, output);
                } else if (transformto.equals(TO_PNG)) {
                    PNGTranscoder t = new PNGTranscoder();
                    t.addTranscodingHint(ImageTranscoder.KEY_MEDIA, "screen");
                    TranscoderInput input = new TranscoderInput(new StringReader(
                            rawSvg));
                    TranscoderOutput output = new TranscoderOutput(outputStream);
                    try {
                        t.transcode(input, output);
                    } catch (Exception e) {
                        // issue with batik here..do not make a big deal
                        _logger.debug(e.getMessage());
                    }
                } else if(transformto.equals(TO_SVG)) {
View Full Code Here

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

  public PngConverter() {
    super("png");
  }

  protected Transcoder createTranscoder() {
    return new PNGTranscoder();
  }
View Full Code Here

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

    }
  }
 
  public static void transformSVGIntoPNG (InputStream inputStream, OutputStream outputStream) {
    // create a PNG transcoder
    PNGTranscoder t = new PNGTranscoder();
   
    // set the transcoding hints
    t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(1000));
    t.addTranscodingHint(PNGTranscoder.KEY_ALLOWED_SCRIPT_TYPES, "*");
    t.addTranscodingHint(PNGTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN, new Boolean(true));
    t.addTranscodingHint(PNGTranscoder.KEY_EXECUTE_ONLOAD, new Boolean(true));
   
    // create the transcoder input
    Reader reader = new InputStreamReader(inputStream);
    TranscoderInput input = new TranscoderInput(reader);
   
    // create the transcoder output
    TranscoderOutput output = new TranscoderOutput(outputStream);
   
    // save the image
    try {
      t.transcode(input, output);
    } catch (TranscoderException e) {
      logger.error("Impossible to convert svg to png: " + e.getCause(), e);
      throw new SpagoBIEngineRuntimeException("Impossible to convert svg to png: " + e.getCause(), e);
    }
  }
View Full Code Here

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

    public void renderPNG(Svg svg, OutputStream out)
            throws TranscoderException, JAXBException, IOException {
        ByteArrayOutputStream bos = null;
        ByteArrayInputStream bis = null;
        try {
            PNGTranscoder t = new PNGTranscoder();
            bos = new ByteArrayOutputStream();
            jaxbContext.createMarshaller().marshal(svg, bos);
            bis = new ByteArrayInputStream(bos.toByteArray());
            TranscoderInput input = new TranscoderInput(bis);
            TranscoderOutput output = new TranscoderOutput(out);
            t.transcode(input, output);
        } finally {
            if (bos != null)
                bos.close();
            bos = null;
            if (bis != null)
View Full Code Here

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

        File file = new File(pngPath);
        InputStream svgStream = new ByteArrayInputStream(svg_xml.getBytes("utf-8"));
          TranscoderInput input = new TranscoderInput(svgStream);
          file.createNewFile();
        outputStream = new FileOutputStream(file);
        PNGTranscoder transcoder = new PNGTranscoder();
        TranscoderOutput output = new TranscoderOutput(outputStream);
      transcoder.transcode(input, output);
      outputStream.flush();
     
      }catch(Exception e){
        throw new RuntimeException(e);
      }finally{
View Full Code Here

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

        svg = svg.replaceAll(":rect", "rect");
        String ext = "";
        Transcoder t = null;
        if (type.equals("image/png")) {
          ext = "png";
          t = new PNGTranscoder();
        } else if (type.equals("image/jpeg")) {
          ext = "jpg";
          t = new JPEGTranscoder();
        } else if (type.equals("application/pdf")) {
          ext = "pdf";
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.