阿萨德撒

package com.kadang.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import org.apache.batik.transcoder.Transcoder;
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;

public class SvgUtil {

	// svg转png
	public static void convertSvgToPng(File svg, File png) throws IOException,
			TranscoderException {
		    InputStream in = new FileInputStream(svg);
	        OutputStream out = new FileOutputStream(png);
	        convertToPng(in, out);
	}

	public static void convertToPng(InputStream in, OutputStream out)
			throws IOException, TranscoderException {
		// 实例一个转换器
		Transcoder transcoder = new PNGTranscoder();
//		Transcoder transcoder2=new JPEGTranscoder();
		//设置转换png图片的大小
		transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(1000));
		try {
			//得到转换器的输入流
			TranscoderInput input = new TranscoderInput(in);
			try {
				//输出流
				TranscoderOutput output = new TranscoderOutput(out);
				System.out.println("转换前");
				//格式转换
				transcoder.transcode(input, output);
				System.out.println("转换完毕");
			} finally {
				out.close();
			}
		} finally {
			in.close();
		}
	}

}

 

posted on 2014-04-04 16:46  魂牵梦莹  阅读(232)  评论(0)    收藏  举报