svg转换工具

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>

 

posted @ 2015-10-01 00:10  rubekid  阅读(1712)  评论(0编辑  收藏  举报