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>

 

相关文章:

  • 2021-07-27
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2021-11-18
猜你喜欢
  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2021-10-04
  • 2021-06-14
  • 2022-12-23
  • 2021-06-25
相关资源
相似解决方案