Package org.apache.batik.transcoder.image

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


  }

  public static void transformSVGIntoJPEG(InputStream inputStream,
      OutputStream outputStream) {
    // create a JPEG transcoder
    JPEGTranscoder t = new JPEGTranscoder();

    // set the transcoding hints
    t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1));
    t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(1000));
    t.addTranscodingHint(JPEGTranscoder.KEY_ALLOWED_SCRIPT_TYPES, "*");
    t.addTranscodingHint(JPEGTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN,
        new Boolean(true));
    t.addTranscodingHint(JPEGTranscoder.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


    }
  }

  public static void transformSVGIntoJPEG (InputStream inputStream,  OutputStream outputStream) {
    // create a JPEG transcoder
    JPEGTranscoder t = new JPEGTranscoder();
   
    // set the transcoding hints
    t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1));
    t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(1000));
    t.addTranscodingHint(JPEGTranscoder.KEY_ALLOWED_SCRIPT_TYPES, "*");
    t.addTranscodingHint(JPEGTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN, new Boolean(true));
    t.addTranscodingHint(JPEGTranscoder.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

   
  }
 
  public static void transformSVGIntoJPEG (InputStream inputStream,  OutputStream outputStream) {
    // create a JPEG transcoder
    JPEGTranscoder t = new JPEGTranscoder();
   
    // set the transcoding hints
    t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1));
    t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(1000));
    t.addTranscodingHint(JPEGTranscoder.KEY_ALLOWED_SCRIPT_TYPES, "*");
    t.addTranscodingHint(JPEGTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN, new Boolean(true));
    t.addTranscodingHint(JPEGTranscoder.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

  public JpgConverter() {
    super("image/jpeg", "jpg");
  }

  protected Transcoder createTranscoder() {
    Transcoder t = new JPEGTranscoder();
    t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, 0.95f);
    return t;
  }
View Full Code Here

   *
   * @throws Exception raised if some errors occur during the elaboration
   */
  public static void SVGToJPEGTransform(InputStream inputStream,  OutputStream outputStream) throws IOException {
    // create a JPEG transcoder
    JPEGTranscoder t = new JPEGTranscoder();
   
    // set the transcoding hints
    t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1));
    t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(1000));
    t.addTranscodingHint(JPEGTranscoder.KEY_ALLOWED_SCRIPT_TYPES, "*");
    t.addTranscodingHint(JPEGTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN, new Boolean(true));
    t.addTranscodingHint(JPEGTranscoder.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) {
      throw new IOException("Impossible to convert svg to jpeg: " + e.getCause());
    }
  }
View Full Code Here

    }
  }

  public static void transformSVGIntoJPEG (InputStream inputStream,  OutputStream outputStream) {
    // create a JPEG transcoder
    JPEGTranscoder t = new JPEGTranscoder();
   
    // set the transcoding hints
    t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1));
    t.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, new Float(1000));
    t.addTranscodingHint(JPEGTranscoder.KEY_ALLOWED_SCRIPT_TYPES, "*");
    t.addTranscodingHint(JPEGTranscoder.KEY_CONSTRAIN_SCRIPT_ORIGIN, new Boolean(true));
    t.addTranscodingHint(JPEGTranscoder.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

        File expFile = new File(uploadTempDir, reqFilePrefix + "." + exportType);
        log.debug("exported file: " + expFile.getCanonicalPath());
        if ("svg".equals(exportType)) {
          outFile(response, expFile);
        } else if ("jpg".equals(exportType)) {
          JPEGTranscoder t = new JPEGTranscoder();
              t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, 1f);
             
              OutputStream ostream = new FileOutputStream(expFile);
              TranscoderOutput output = new TranscoderOutput(new FileOutputStream(expFile));

              // Perform the transcoding.
              t.transcode(new TranscoderInput(svgFile.toURI().toString()), output);
              ostream.flush();
              ostream.close();
             
          outFile(response, expFile);
        } else if (exportType.equals("png")
View Full Code Here

        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";
          t = (Transcoder) new PDFTranscoder();
        } else if (type.equals("image/svg+xml"))
          ext = "svg";
View Full Code Here

        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";
          t = (Transcoder) new PDFTranscoder();
        } else if (type.equals("image/svg+xml"))
          ext = "svg";
View Full Code Here

     * Converts a SVG image to a JPEG bitmap.
     * @param image the SVG image
     * @return a byte array containing the JPEG image
     */
    public static byte[] convertToJPEG(XMLImage image) {
        JPEGTranscoder transcoder = new JPEGTranscoder();
        /* TODO Disabled to avoid side-effect due to the mixing of source and target resolutions
         * This should be reenabled when it has been determined how exactly to handle this
        transcoder.addTranscodingHint(ImageTranscoder.KEY_PIXEL_UNIT_TO_MILLIMETER,
                new Float(25.4f / 300)); //300dpi should be enough for now.
        */
        transcoder.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(0.9f));
        TranscoderInput input = new TranscoderInput(image.getDocument());
        ByteArrayOutputStream baout = new ByteArrayOutputStream(16384);
        TranscoderOutput output = new TranscoderOutput(baout);
        try {
            transcoder.transcode(input, output);
            return baout.toByteArray();
        } catch (TranscoderException e) {
            log.error(e);
            return null;
        }
View Full Code Here

TOP

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

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.