Transcode SVG to JPEG

223 Views Asked by At

the original image was svg, but i can only upload png-format not svg-format

my picture in SVG format include the latest data 122.6 but in JPEG format the last data point is 122.1

How can I convert the image in svg-format to jpeg-format without the lost of the latest data renderer ? padding margins ? size ?

What is wrong in my code ??

best ghost

package helix;

import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.batik.transcoder.image.JPEGTranscoder;
import org.apache.fop.svg.PDFTranscoder;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.ext.awt.image.codec.*;


public class genesisMATPIsvg2jpg {
    
    
    
    public static void main(String[] args) throws Exception {
        
                
        //Step -1: We read the input SVG document into Transcoder Input
        String svg_URI_input = new File(basePath + "/var/gWebClient/Materialkostenindex2015=100.svg").toURL().toString();
        TranscoderInput input_svg_image = new TranscoderInput(svg_URI_input);        
        //Step-2: Define OutputStream to JPG file and attach to TranscoderOutput
        OutputStream jpg_ostream = new FileOutputStream(basePath + "/var/gWebClient/Materialkostenindex2015=100.jpeg");
        TranscoderOutput output_jpg_image = new TranscoderOutput(jpg_ostream);              
        // Step-3: Create JPEGTranscoder and define hints
        JPEGTranscoder my_converter = new JPEGTranscoder();
        
        Object jpegQuality1 = new Float(800);
        Object jpegQuality2 = new Float(600);
        
        my_converter.addTranscodingHint(JPEGTranscoder.KEY_WIDTH, jpegQuality1);
        my_converter.addTranscodingHint(JPEGTranscoder.KEY_HEIGHT, jpegQuality2);
        
        my_converter.addTranscodingHint(JPEGTranscoder.KEY_QUALITY,new Float(0.9));
        // Step-4: Write output
        my_converter.transcode(input_svg_image, output_jpg_image);
        // Step 5- close / flush Output Stream
        jpg_ostream.flush();
        jpg_ostream.close();        
    }
}
0

There are 0 best solutions below