-
-
Save eclecticlogic/7890297 to your computer and use it in GitHub Desktop.
public BufferedImage createImageFromSVG(String svg) { | |
Reader reader = new BufferedReader(new StringReader(svg)); | |
TranscoderInput svgImage = new TranscoderInput(reader); | |
BufferedImageTranscoder transcoder = new BufferedImageTranscoder(); | |
transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) component.getWidth()); | |
transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) component.getHeight()); | |
try { | |
transcoder.transcode(svgImage, null); | |
} catch (TranscoderException e) { | |
throw Throwables.propagate(e); | |
} | |
return transcoder.getImage(); | |
} |
while I'm using your BufferedImageTranscoder, I encountered this problem; The element type "link" must be terminated by the matching end-tag ""
You can also convert svg to png format without the use of Batik Transcoder. Follow below link:
https://nupur28ag.blogspot.in/
BufferedImage input_image = null;
input_image = ImageIO.read(new File("Convert_to_PNG.svg")); //read svginto input_image object
File outputfile = new File("imageio_png_output.png"); //create new outputfile object
ImageIO.write(input_image, "PNG", outputfile);
You can also convert svg to png format without the use of Batik Transcoder. Follow below link:
Nop. It doesn't work. ImageIO#read does not support SVG format.
You can find the supported formats following this link https://docs.oracle.com/javase/tutorial/2d/images/loadimage.html
What version of apache batik are using?, I can not find the class BufferedImageTranscoder