标签:
package com.rubekid.springmvc.utils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import org.apache.batik.transcoder.TranscoderException; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; import org.apache.batik.transcoder.image.PNGTranscoder; /** * svg工具 * @author rubekid * */ public class SvgUtils { public static byte[] toPng(byte[] svgByteArray) throws TranscoderException, IOException{ return toPng(new ByteArrayInputStream(svgByteArray)); } public static byte[] toPng(InputStream inputStream) throws TranscoderException, IOException{ PNGTranscoder transcoder = new PNGTranscoder(); TranscoderInput input = new TranscoderInput(inputStream); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); TranscoderOutput output = new TranscoderOutput(outputStream); transcoder.transcode(input, output); outputStream.close(); return outputStream.toByteArray(); } }
<dependency> <groupId>batik</groupId> <artifactId>batik-transcoder</artifactId> <version>1.6-1</version> </dependency>
标签:
原文地址:http://www.cnblogs.com/rubekid/p/4850563.html