Package org.apache.batik.transcoder.image

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


        TranscoderInput input = new TranscoderInput(svg);

        TranscoderOutput output = new TranscoderOutput(jpeg);

        // Create a JPEG transcoder
        Transcoder t = new JPEGTranscoder();

        // Set the transcoding hints.
        t.addTranscodingHint(JPEGTranscoder.KEY_QUALITY, new Float(1.0));

        // Save the image.
        t.transcode(input, output);

        // Flush and close the stream.
        svg.close();
        jpeg.flush();
        jpeg.close();
View Full Code Here


    protected Transcoder getTranscoder(){
        switch(code) {
            case PNG_CODE:
                return new PNGTranscoder();
            case JPEG_CODE:
                return new JPEGTranscoder();
            case TIFF_CODE:
                return new TIFFTranscoder();
            case PDF_CODE:
                try {
                    Class pdfClass = Class.forName("org.apache.fop.svg.PDFTranscoder");
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();
                    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 {
                                currentExportPath = f;
                                OutputStream ostream =
                                    new BufferedOutputStream(new FileOutputStream(f));
                                trans.writeImage(img, new TranscoderOutput(ostream));
                                ostream.flush();
                                ostream.close();
                            } catch (Exception ex) { }
                            statusBar.setMessage
                                (resources.getString("Message.done"));
View Full Code Here

    protected Transcoder getTranscoder(){
        switch(code) {
            case PNG_CODE:
                return new PNGTranscoder();
            case JPEG_CODE:
                return new JPEGTranscoder();
            case TIFF_CODE:
                return new TIFFTranscoder();
            case PDF_CODE:
                try {
                    Class pdfClass = Class.forName("org.apache.fop.svg.PDFTranscoder");
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

        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

        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

        */
        ImageTranscoder t = null;
        if (mimeType.equals("image/jpg") ||
            mimeType.equals("image/jpeg") ||
            mimeType.equals("image/jpe")) {
            t = new JPEGTranscoder();
            t.addTranscodingHint(JPEGTranscoder.KEY_XML_PARSER_CLASSNAME,
                                 "org.apache.crimson.parser.XMLReaderImpl");
        } else if (mimeType.equals("image/png")) {
            t = new PNGTranscoder();
            t.addTranscodingHint(PNGTranscoder.KEY_XML_PARSER_CLASSNAME,
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();
                    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.setColor(Color.white);
                    g2d.fillRect(0, 0, w, h);
                    g2d.drawImage(buffer, null, 0, 0);
                    new Thread() {
                        public void run() {
                            try {
                                currentExportPath = f.getCanonicalPath();
                                OutputStream ostream =
                                    new BufferedOutputStream(new FileOutputStream(f));
                                trans.writeImage(img, new TranscoderOutput(ostream));
                                ostream.flush();
                                ostream.close();
                            } catch (Exception ex) { }
                            statusBar.setMessage
                                (resources.getString("Message.done"));
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.