简体   繁体   中英

how to convert png to svg using apache batik in java?

i want to convert my png image file into svg and store in file system, i not found any apropriate answer if anyone have the solution please share.

i use below code but not work SVGTranscoder t = new SVGTranscoder();

    t.addTranscodingHint(SVGTranscoder.KEY_FORMAT, true);

    String svgURI = new File(inputFilePath).toURL().toString();

    InputStream inputStream = new FileInputStream(inputFilePath);
    Reader inputStreamReader = new InputStreamReader(inputStream);
    TranscoderInput input = new TranscoderInput(inputStreamReader);

    OutputStream ostream = new FileOutputStream(outputFilePath);
    Writer outputStreamWriter = new OutputStreamWriter(ostream);
    TranscoderOutput output = new TranscoderOutput(outputStreamWriter);

    t.transcode(input, output);

    ostream.flush();
    ostream.close();
    System.exit(0);

Try this:

Converter converter = new Converter("input.png");
// Prepare conversion options for target format SVG
ConvertOptions convertOptions = new FileType().fromExtension("svg").getConvertOptions();
// Convert to SVG format
converter.convert("output.svg", convertOptions);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM